strUserName = new String(strUserName.getBytes("ISO8859-1"),"GBK");

解决方案 »

  1.   

    <%@ page contentType="text/html; charset=GBK" %><meta http-equiv="Content-Type" content="text/html; charset=gb2312">
      

  2.   

    <%@ page contentType="text/html; charset=GBK" %><meta http-equiv="Content-Type" content="text/html; charset=gb2312">strUserName = new String(strUserName.getBytes("ISO8859-1"),"GBK");
      

  3.   

    已经找了几篇看过了,
    <%@ page contentType="text/html; charset=GBK" %>
    这种方法是不行的,tomcat出现异常,multiple charset的异常,还有一种方法不错,从根子上解决,改tomcat的源代码,将ISO-8859-1改成GBK的,改完后编译,但问题是,那么多的类必须一起编译才能通过,源代码的类是HttpRequestBase.java,单独编译就有八十多个错误。这需要写一个批处理文件啊。就剩下一种方法没用了,
    strUserName = new String(strUserName.getBytes("ISO8859-1"),"GBK");
    但内容太多,就只能这样了吗?第一种方法为什么不行呢?有点奇怪啊。
      

  4.   

    对于最后一种方法:Tomcat自带的例子中有解决字符集的例子。
    在:C:\Program Files\Apache Group\Tomcat 4.1\webapps\examples\WEB-INF\classes\filters\SetCharacterEncodingFilter.java文件中。它是用Filter解决的,在处理任何Client的请求前,Filter总是先被调用,所以只在一个修改就可以了。你只需要将字符集改为GBK即可。这是使用:
    public void doFilter(ServletRequest request, ServletResponse response,
        FilterChain chain)
        throws IOException, ServletException {        
            request.setCharacterEncoding("GBK");
            chain.doFilter(request,response);
           
        }
      

  5.   

    这里有很详细的解释:http://expert.csdn.net/Expert/topic/1085/1085595.xml?temp=.7492029
      

  6.   

    我的qq是6910083。我是一名经理,现在招聘兼职,待遇按一天5百元计算。有兴趣的朋友找我直接聊聊,大家可以成为朋友,长期合作。要求是JAVA水平较高,通晓JAVA相关的技术,北京地区。谢谢
      

  7.   


    今天上午重新试验一下,特别特别简单的一个程序,一个html页面输入姓名,提交后的jsp页面却出现下面的信息,org.apache.jasper.JasperException: Unsupported encoding: gb2312 
    但我down的其他web应用程序却没有这个问题,先面是源代码:
    enter.html:
    <html>
    <meta content="text/html ;charset=gb2312" /><body>
    <h1>this page is checked for chinese</h1>
    <form name="china" method="POST" action="show.jsp">
      <input type="text" name="name" />
      <input type="submit" name="submit" value="submit"/>
    </form>
    </body>show.jsp:
    <%@ page language="java" contentType="text/html ; charset=gb2312 "%>
    <%String show=request.getParameter("name") ;
      byte[] b=show.getBytes("ISO-8859-1");
      String s=new String(b,"GBK")%>
    welcome <%= s%> to our site!
      

  8.   

    哦,忘了说了,
    <meta content="text/html ;charset=gb2312" />
    这行我写错了。
    改成<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    String s=new String(b,"GBK")后忘了加分号“;”了,
    之后没有异常了。
    但是点了submit后,弹出对话框:“是保存还是打开?”
    打开:在vc窗口下打开,没有乱码,但任何html语言照搬,比如如果原来有<html>,仍会显示。
    保存:保存在文件加下,为asp文件。
    这怎么跟vc扯上了?