我用STRUTS框架做了个论坛,在后台输入数据,然后在前台就可以显示了,输入英文时一切正常,但是输入中文,前台就会出现乱码,但是在MYSQL里却还是显示中文,请教各位怎么解决

解决方案 »

  1.   

    乱码问题,在页面中设定编码,不如"GBk"
      

  2.   

    你把提交方式改下,把get改为post试下。
      

  3.   

    写一个编码过滤器,懒的话就复制tomcat自带的就可以,要配置一下web.xmlpublic 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);    }
    }配置web.xml:
      <filter>
            <filter-name>Set Character Encoding</filter-name>
            <filter-class>com.cn.nst.filter.SetCharacterEncodingFilter</filter-class>
            <init-param>
                <param-name>encoding</param-name>
                <param-value>UTF-8</param-value>
            </init-param>
        </filter>
    <filter-mapping>
            <filter-name>Set Character Encoding</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>