首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

编码有关问题老生常问

2012-02-04 
编码问题老生常问eclipse3.1+myeclipse4.1+tomcat5在web.xml中加入filterfilter-name SetCharacterEnc

编码问题老生常问
eclipse3.1+myeclipse4.1+tomcat5

在web.xml中加入
<filter>
<filter-name> SetCharacterEncoding </filter-name>
<filter-class> com.talkweb.tb.filter.SetCharacterEncodingFilter </filter-class>
<init-param>
<param-name> encoding </param-name>
<param-value> GBK </param-value>
</init-param>
<init-param>
<param-name> enable </param-name>
<param-value> true </param-value>
</init-param>
    </filter>
    <filter-mapping>
    <filter-name> SetCharacterEncoding </filter-name>
    <url-pattern> /* </url-pattern>
    </filter-mapping>

对应的filter代码为

public   class   SetCharacterEncodingFilter   implements   Filter   {

        protected   FilterConfig   filterConfig;

        protected   String   encodingName;

        protected   boolean   enable;

        public   void   init(FilterConfig   filterConfig)   throws   ServletException   {
                this.filterConfig   =   filterConfig;
                loadConfigParams();
        }

        private   void   loadConfigParams()   {
                //   encoding
                this.encodingName   =   this.filterConfig.getInitParameter( "encoding ");
                //   filter   enable   flag...
                String   strIgnoreFlag   =   this.filterConfig.getInitParameter( "enable ");
                if   (strIgnoreFlag.equalsIgnoreCase( "true "))   {
                        this.enable   =   true;
                }   else   {
                        this.enable   =   false;
                }
        }

        public   void   doFilter(ServletRequest   request,   ServletResponse   response,
                        FilterChain   chain)   throws   IOException,   ServletException   {
                if   (this.enable)   {
                        request.setCharacterEncoding(this.encodingName);
                }
                chain.doFilter(request,   response);
        }

        public   void   destroy()   {
        }

}

页面如下

<%@   page   contentType= "text/html;   charset=GBK "   %>


<%%>
<%=request.getParameter( "keyword ")%>
<html>
<head>
<title> </title>
</head>
<body>
<form>
<table   width= "100% "     border= "0 "   cellspacing= "0 "   cellpadding= "3 ">
    <tr>
        <td   height= "20 "   width= "35% "> &nbsp;   查询:
<input   type= "text "   name= "keyword "   value= " "   size= "20 "> &nbsp;
<input   type= "submit "     value= "11 "   size= "20 ">
</td>

</table>

</form>
</body>
</html>

输入后在页面显示乱码!!!

该如何解决????

[解决办法]
帮顶
[解决办法]
到我的blog上找

http://blog.csdn.net/coolzeze
[解决办法]
反正weblogic是可能出现这个问题的,

使用变码方式不对就是乱麻,GBK与UTF-8的不同
[解决办法]
来晚了啊,问题都解决了,呵呵

热点排行