1.demo01.jsp和demo02.jsp编码必须都是GBK2.换成UTF-8 看看3.写的没问题,可能和开发软件版本有关

解决方案 »

  1.   

    demo01.jsp中加上<%@ page pageEncoding="GBK"%>
      

  2.   

    如果是Form提交的话:
    --------------------------------------------
    public void doFilter(ServletRequest request, ServletResponse response,
    FilterChain chan) throws IOException, ServletException
    {
    response.setContentType("text/html;charset=" + this.encoding);

    //获取提交的发式是Post还是Get
    String method = ((HttpServletRequest)request).getMethod();

    if(method.equalsIgnoreCase("post"))
    {
    request.setCharacterEncoding(this.encoding);
    }
    else
    {
    Enumeration<String> enu = request.getParameterNames();//获取所有的参数的名称,是一个枚举
    while(enu.hasMoreElements())
    {
    String name = enu.nextElement();
    String[] value = request.getParameterValues(name); //根据参数名称获取值,是一个字符串数组

    for(int i=0;i<value.length;i++)
    {
    value[i] = toUTF8(value[i]);
    }
    }
    }

    chan.doFilter(request, response);
    }
      

  3.   

    public String toUTF8(String inStr) throws UnsupportedEncodingException
    {
    String outStr = "";
    if(inStr != null)
    {
    outStr = new String(inStr.getBytes("iso-8859-1"),"utf-8");
    }
    return outStr;
    }
      

  4.   

    楼上的,这个地方我觉得有问题.
    else
    {
    Enumeration<String> enu = request.getParameterNames();//获取所有的参数的名称,是一个枚举
    while(enu.hasMoreElements())
    {
    String name = enu.nextElement();
    String[] value = request.getParameterValues(name); //根据参数名称获取值,是一个字符串数组

    for(int i=0;i<value.length;i++)
    {
    value[i] = toUTF8(value[i]);
    }
    }
    }
    请求的参数值是重新编码了,但是对request对象没有效果吧?好象是在重编码request的参数值拷贝.
      

  5.   

    TangAlex,你的可以用,但是还是有点不明白你的思路是把所有request对象里面的参数值提取出来进行重编码,对吗?但是我觉得String[] value=request.getParameterValues(name);只是把提取出来的值进行重编码,不会影响到request对象里面的参数啊.是不是我理解错了?