<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    all gone

    all gone

    #

    JSP 處理MySQL數(shù)據(jù)庫時(shí)的中文問題

    以前遇到JSP 處理MySQL數(shù)據(jù)庫時(shí)的中文問題時(shí),采取的是很笨的一種方法,直接用字符串編碼轉(zhuǎn)換函數(shù)進(jìn)行轉(zhuǎn)換,這次從網(wǎng)上搜了一下,找到了一個(gè)使用Filter的可行方法。在Tomcat 5.5+ MySQL4.0.16下通過。

    filter類源碼是從網(wǎng)上找的,如下
    /**
     *
     */
    package com.lzy;

    import java.io.IOException;
    import javax.servlet.Filter;
    import javax.servlet.FilterChain;
    import javax.servlet.FilterConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;

    /**
     * @author lzy
     *
     */
    public class SetCharacterEncodingFilter implements Filter {
     
     protected String encoding = null;
        protected FilterConfig filterConfig = null;
        protected boolean ignore = true;


     /* (non-Javadoc)
      * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
      */
     public void init(FilterConfig filterConfig) throws ServletException {
      // TODO Auto-generated method stub
      this.filterConfig = filterConfig;
         this.encoding = filterConfig.getInitParameter("encoding");
         String value = filterConfig.getInitParameter("ignore");
         if (value == null)
          this.ignore = true;
         else if (value.equalsIgnoreCase("true"))
          this.ignore = true;
         else if (value.equalsIgnoreCase("yes"))
          this.ignore = true;
         else
          this.ignore = false;


     }

     /* (non-Javadoc)
      * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
      */
     public void doFilter(ServletRequest request, ServletResponse response,
       FilterChain chain) throws IOException, ServletException {
      
      // TODO Auto-generated method stub
      if (ignore || (request.getCharacterEncoding() == null)) {
       String encoding = selectEncoding(request);
       if (encoding != null)
        request.setCharacterEncoding(encoding);
      }
      chain.doFilter(request, response);
     }

     /* (non-Javadoc)
      * @see javax.servlet.Filter#destroy()
      */
     public void destroy() {
      // TODO Auto-generated method stub
      
      this.encoding = null;
         this.filterConfig = null;


     }
     
      protected String selectEncoding(ServletRequest request) {

             return (this.encoding);

         }


    }

    在web.xml 文件中作如下設(shè)置:(我使用的是Struts框架)
    <filter>
    <filter-name>Encoding</filter-name>
    <filter-class>com.lzy.SetCharacterEncodingFilter</filter-class>
    <init-param>
    <param-name>encoding</param-name>
    <param-value>GBK</param-value>
    </init-param>
    </filter>

    <filter-mapping>
    <filter-name>Encoding</filter-name>
    <servlet-name>action</servlet-name>
    </filter-mapping>
    <filter-mapping>
    <filter-name>Encoding</filter-name>
    <url-pattern>*.jsp</url-pattern>
    </filter-mapping>


    最后,連接數(shù)據(jù)庫時(shí),使用下面的url:
    jdbc:mysql://localhost:3306/數(shù)據(jù)庫名?useUnicode=true&characterEncoding=GBK

    posted @ 2005-12-18 22:57 all gone 閱讀(481) | 評(píng)論 (0)編輯 收藏

    Spring之Hello World

    1.下載Spring相關(guān)的開發(fā)包
    下載地址:http://sourceforge.net/project/showfiles.php?group_id=73357
    有spring-framework-1.2.6-with-dependencies.zip,一個(gè)是spring-framework-1.2.6.zip,最好下載with-dependencies的,里面有另外一些附加包,下載后解壓縮,dist目錄下是spring自身的jar,lib目錄下是附加的jar。
    2.新建Java Project,將spring.jar(dist目錄下)和commons-logging.jar(lib目錄下)添加到project的build path中。
    3.新建POJO Bean類:HelloBean
    //HelloBean.java
    /**
     *
     */
    package com.lzy;

    /**
     * @author lzy
     *
     */
    public class HelloBean{
     
     private String hello;
     
     public void sayHello(){
      System.out.println(this.getHello());
     }

     /**
      * @return Returns the hello.
      */
     public String getHello() {
      return hello;
     }

     /**
      * @param hello The hello to set.
      */
     public void setHello(String hello) {
      this.hello = hello;
     }
     

    }


    4.新建文件bean.xml,將在這個(gè)XML文件中為一個(gè)HelloBean的實(shí)例的hello屬性賦值。
    //bean.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "<beans>
    <description>Spring Quick Start</description>
    <bean id="helloBean" class="com.lzy.HelloBean">
      <property name="hello">
       <value>hello world</value>
      </property>
    </bean>
    </beans>

    5.新建測試類:TestSpring
    //TestSpring.java
    /**
     *
     */
    package com.lzy;

    import java.util.Locale;

    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.FileSystemXmlApplicationContext;

    /**
     * @author lzy
     *
     */
    public class TestSpring {

     /**
      * @param args
      */
     public static void main(String[] args) {
      // TODO Auto-generated method stub
      
      ApplicationContext ctx=new FileSystemXmlApplicationContext("bean.xml");
        HelloBean hello=(HelloBean)ctx.getBean("helloBean");
      hello.sayHello();
     }

    }


    6.運(yùn)行測試類:
        如果沒有出錯(cuò),輸出中將會(huì)看到“hello world”。

    posted @ 2005-12-14 22:07 all gone 閱讀(1049) | 評(píng)論 (0)編輯 收藏

    僅列出標(biāo)題
    共17頁: First 上一頁 5 6 7 8 9 10 11 12 13 下一頁 Last 
    主站蜘蛛池模板: 亚洲av永久无码精品国产精品| 亚洲区精品久久一区二区三区| 国产V亚洲V天堂无码久久久 | 国产精品亚洲精品日韩动图| 免费人妻av无码专区| 久久免费国产精品一区二区| 国产成人亚洲精品| 亚洲人成无码网WWW| 国产成人亚洲综合无| 亚洲成a人片在线观看无码| 91免费播放人人爽人人快乐| 香蕉视频在线观看免费| 91天堂素人精品系列全集亚洲| 99久久99久久精品免费观看| 亚洲精品天堂无码中文字幕| 日本免费福利视频| 深夜特黄a级毛片免费播放| 亚洲国产精品一区| 亚洲AV日韩精品一区二区三区 | 国产精品亚洲va在线观看| 亚洲电影一区二区| 222www免费视频| 亚洲国产亚洲综合在线尤物| 久久亚洲AV无码西西人体| 久久久久久久91精品免费观看| 中文永久免费观看网站| 亚洲区小说区图片区QVOD| 久久成人免费大片| 小说区亚洲自拍另类| 亚洲日本va中文字幕久久| 麻豆国产VA免费精品高清在线| 免费无码国产V片在线观看| 亚洲熟妇无码久久精品| 亚洲毛片αv无线播放一区| 日本牲交大片免费观看| 久久久久久久91精品免费观看| 久久久久久久久久国产精品免费 | 野花香高清视频在线观看免费 | 69视频免费在线观看| 亚洲日韩一区二区三区| 亚洲国产精品热久久|