<%@   page   contentType="text/html;charset=gb2312"   language="java"   %>    
<jsp:useBean id="user" scope="page" class="com.Ts4Bean"/>
<jsp:setProperty name="user" property="*"/>
<%@ include file="trans.jsp"%>
<html> 
<body> 
提交成功:<br>
<hr>
使用bean属性方法:<br>
用户名:<%=session.getAttribute("name")%><br>
班级:<%=user.getBanji()%><br>
<br>
<hr>
</body> 
</html> 代码如上
在班级这栏中调用的是前页的一个隐藏字段的值 显示为乱码
请达人帮忙

解决方案 »

  1.   

    Filter实现版:
    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);     } 

    配置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>
      

  2.   

    在前一个页面中
    <%@page pageEncoding="gbk"%>
      

  3.   

    charset=gb2312改成gbk,
    然后用过滤器。这样,post提交的都没有问题。但如果你是get提交,就不行了。
    get的话这样试试
    1.new String(string.getBytes("GBK"), "UTF-8")
    2.chi = java.net.URLEncoder.encode(chi, "ISO-8859-1");
                chi = java.net.URLDecoder.decode(chi, "GBK");
    实在不行就编码,然后解码。
      

  4.   

    关于中文问题,请看下帖http://community.csdn.net/Expert/topic/5404/5404769.xml?temp=.9756739
      

  5.   

    我是include文件出现乱码,用了<%@page pageEncoding="gbk"%>很管用,谢谢啦