我在URL中使用的是escape,但是我用的是s2sh结构,在action中获取的是乱码(%...),用unescape怎么解决??
或者说ajax中文乱码怎么解决?  急!!高手帮我看看!!

解决方案 »

  1.   

    在WEB.XML中配置过滤的类
     <filter>
        <filter-name>encode</filter-name>
        <filter-class>web.Encode</filter-class>
      </filter>
      <filter-mapping>
        <filter-name>encode</filter-name>
        <url-pattern>*.do</url-pattern> 
      </filter-mapping>
    可以过滤所有.do结尾的请求
    public class Encode implements Filter { public void destroy() {
    // TODO Auto-generated method stub

    } public void doFilter(ServletRequest arg0, ServletResponse arg1,
    FilterChain arg2) throws IOException, ServletException {
    arg0.setCharacterEncoding("gbk");
    //System.out.println("过滤一下");
    arg2.doFilter(arg0, arg1);
    } public void init(FilterConfig arg0) throws ServletException {
    // TODO Auto-generated method stub

    }
      

  2.   

    action中用了,但是要在action中使用unescape,问如何使用??
      

  3.   

    在URL中的字符串用encodURI(String); 试下;
      

  4.   

    首先在java代码中确定接受到的字节数是多少
    1.比如我传递了参数“1中国2”
    2.在java中接受到该参数,比如
       String sTestParamerter = request.getParameter("TestParameter");
       int nBytesLength = sTestParamerter.getBytes().length;
       
       开始分析:
      如果 nBytesLength=4,说明编码是采用了iso-8859-1(中文也采用一个字节编码)
      如果 nBytesLength=6,说明采用了GBK编码(一个中文采用2个字节编码)
      如果 nBytesLength=8,说明采用了UTF-8编码(1个中文采用了3个字节的编码)基本我们常用的就是这3个编码,当我们使用request获取参数的时候,如果request上没有设置过编码,那么Tomcat应用服务器默认是采用iso-8859-1编码的,可以采用request.setCharacterEncoding("UTF-8")来试试,因为中文的时候必须使用GBK或者UTF-8编码