以前我是用jsp+javaBean,这些代码在jsp中没事,在jsp中的编码是<%@ page language="java" pageEncoding="GBK"%>
但写到servlet中就不行了?userName不能正确显示                response.setContentType("text/html"); 
response.setCharacterEncoding("GBK");  String user = Convert.gbToISO(request.getParameter("userName"));
String password = request.getParameter("password");
PrintWriter out = response.getWriter(); out.println("用户注册成功!");
out.println("用户:"+user);
out.println("密码:"+password);
//response.sendRedirect("/product/success.jsp");
out.flush();
out.close();
怎么回事?请指点

解决方案 »

  1.   

    还加一句
                  response.setContentType("text/html"); 
    response.setCharacterEncoding("GBK"); 
    request.setCharacterEncoding("GBK"); 
      

  2.   

    先在系统中输出相关值,从而确认是request还是reponse乱码。第二点确认是用什么方式提交?post还是get,第三确认编辑工具保存的默认编码。第四确认jsp设置的编码。第五点确认你的第统编码。不过是可能的我想你可能是request出现的乱码。你可以实用强转
    String str=new String(str.getByte("ISO-8859-1","GBK"))
    不太记的参数值了。大概是这样的吧。自已查下
      

  3.   

    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException { response.setContentType("text/html"); 
    response.setCharacterEncoding("GBK"); 
    request.setCharacterEncoding("GBK");

    String user = Convert.gbToISO(request.getParameter("userName"));
    String password = request.getParameter("password");
    PrintWriter out = response.getWriter(); out.println("用户注册成功!");
    out.println("用户:"+user);
    out.println("密码:"+password);
    //response.sendRedirect("/product/success.jsp");
    out.flush();
    out.close();
    }还是不行啊~
    Convert.gbToISO();这个方法就是new String(gb.getBytes("GBK"),"ISO-8859-1"); 
    编辑工具保存的默认编码是GBK
      

  4.   

    加上request.setCharacterEncoding("GBK"); 
      

  5.   

    把Convert.gbToISO();这个方法去掉就行了,不知道为什么?