狼愛上貍

          我胡漢三又回來了

          tomcat 5.0.28的問題

          1.配置成首頁的問題

          ? ??????? <Logger className="org.apache.catalina.logger.FileLogger"
          ???????????????? directory="logs"? prefix="localhost_log." suffix=".txt"
          ??????????? timestamp="true"/>
          ?????? ?這里增加:
          ???????? <Context path="" docBase="C:/Tomcat/webapps/myweb" debug="0" reloadable="true" crossContext="true"/>

          ? 要說的是myweb/web-inf/web.xml的文件最好改下名,我的從weblogic轉過來,看了很多論壇,因為這里沒改名,一直錯誤,還不知道怎回事,改了名就好了,該是沖突問題。

          2. 亂碼問題

          如果你沒有亂碼,不用看,有了亂碼,你就成亂麻,總得要解決,現在論壇有說這,有說那,只要解決了你的難題的,就是好方案。

          我的問題時,從數據庫中讀出沒亂碼,寫入出現亂碼,我的方案是:

          (1).在filters中做個SetCharacterEncodingFilter.java的bean文件。

          package filters;

          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;
          import javax.servlet.UnavailableException;

          public class SetCharacterEncodingFilter implements Filter{
          protected String encoding = null;
          protected FilterConfig filterConfig = null;
          protected boolean ignore = true;

          public void destroy() {
          ?this.encoding = null;
          ?this.filterConfig = null;
          }

          public void doFilter(ServletRequest request, ServletResponse response,
          FilterChain chain)
          throws IOException, ServletException {

          // Conditionally select and set the character encoding to be used
          if (ignore || (request.getCharacterEncoding() == null)) {
          ?String encoding = selectEncoding(request);
          ?if (encoding != null)
          ?? request.setCharacterEncoding(encoding);
          }

          // Pass control on to the next filter
          chain.doFilter(request, response);
          }

          public void init(FilterConfig filterConfig) throws ServletException {

          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;
          }

          protected String selectEncoding(ServletRequest request) {
          return (this.encoding);
          }
          }

          編譯上段代碼時,要在classpath中注冊servlet.jar文件。
          (2).在web.xml中引入:

          <filter>
           <filter-name>Set Character Encoding</filter-name>
           <filter-class>filters.SetCharacterEncodingFilter</filter-class>
           <init-param>
            <param-name>encoding</param-name>
            <param-value>GBK</param-value>
           </init-param>
          </filter>

          <filter-mapping>
           <filter-name>Set Character Encoding</filter-name>
           <url-pattern>/*</url-pattern>
          </filter-mapping>

          (3)在server.xml中修改

          ??????????????? port="8080"??maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
          ?????????????? enableLookups="false" redirectPort="8443" acceptCount="100"
          ?????????????? debug="0" connectionTimeout="20000"
          ?????????????? disableUploadTimeout="true" URIEncoding="ISO-8859-1" />

          ???? 有種說法是把URIEncoding="ISO-8859-1"可換成URIEncoding="GBK",自己測試,對的就是硬道理。

          最后順便說下mysql-connector-java-5.0.3-bin.jar的jdbc連接代碼,與以前低版本的不一樣。

          String sDBDriver="com.mysql.jdbc.Driver";
          String sConnStr="jdbc:mysql://localhost:3306/gain?user=root&password=password";


          posted on 2006-10-12 23:08 狼愛上貍 閱讀(275) 評論(0)  編輯  收藏 所屬分類: JAVA

          主站蜘蛛池模板: 日土县| 东港市| 吉木乃县| 化德县| 桦南县| 天水市| 惠东县| 丹棱县| 吉木乃县| 凤阳县| 揭西县| 子长县| 神木县| 盐池县| 沾益县| 雷州市| 衡山县| 旌德县| 西乌| 独山县| 桦甸市| 侯马市| 武定县| 延吉市| 个旧市| 辽中县| 施秉县| 辽宁省| 潢川县| 交城县| 抚州市| 淳化县| 马边| 金湖县| 高唐县| 晴隆县| 万山特区| 新河县| 康保县| 石景山区| 侯马市|