小弟遇到这样的难题:1.jsp
<%@ page contentType="text/html; charset=GB2312" %>
<%@ page language="java" %>
<html>
    <head>
    <title>写邮件</title>
    </head>
<BODY>
<FORM name="form1" methold="post" action="2.jsp">
<P>简单邮件发送机制</P><TABLE width="80%" align="center" height="70%">
<table>
<TR height="25" width="10%"><TD width="20%" >收件人:</TD><TD width="*" align="left"><input type="text" name="takename" size="100" align="left">  </TD>
</TR>
</table>
<table>
<input type="submit" value="submit" name="submit"> 
<input type="reset" value="清除重写" name="clear"> 
</table>
</TABLE>
</form>
</body>
</html>
2.jsp
<%@ page contentType="text/html; charset=GB2312" %>
<html>
<head>
<title>邮件发送</title>
</head>
<body>
<%
String takename=request.getParameter("takename");
out.println("我是我:"+takename);
%>
<br>
我是 我<%=takename%>
</body>
</html>
当2 显示1 中输入的中文时,变成“????”
当把<%@ page contentType="text/html; charset=GB2312" %> 这一句去掉时:
则全部显示乱码,但是在浏览器的 查看---编码---简体中文   则显示正常!但是一刷新又全部是乱码!网上的方法也试过,效果不是很好!系统平台是:2000,JDK1.4.02,Tomcat5.0
请各位帮忙啊,我快郁闷死了!!

解决方案 »

  1.   

    2.jsp取数据之前加一行request.setCharacterEncoding("gb2312");
      

  2.   

    加一个Filter:public void doFilter(ServletRequest srequest, ServletResponse sresponse,
    FilterChain chain) throws IOException, ServletException {

    HttpServletRequest request = (HttpServletRequest) srequest;
    request.setCharacterEncoding("gb2312");
    chain.doFilter(srequest, sresponse);
    }
      

  3.   

    问题得到了解决啊,在传递参数值的时候,将ISO编码转换为GB2312,而后显示就好了!
    String takename=request.getParameter("takename");
    String gb = new String(takename.getBytes("ISO-8859-1"),"gb2312"); 
    这样就OK了!就此结帖~