日期:2014-05-17  浏览次数:20805 次

url 中文参数的一个问题
web.xml中
Java code
<filter>
        <filter-name>encodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>        
        </init-param>
    </filter>


jsp中

Java code
<%@page contentType="text/html;charset=UTF-8" pageEncoding="utf-8"%>
<a href="read.action?chapter=%E8%BF%99%E4%B8%AA%E5%8F%AF%E4%BB%A5%E6%9C%89" >这个可以有</a>


服务器端
Java code
String chapter=getRequest().getParameter("chapter");
        System.out.println("chapter跳转值:"+chapter);
        try{
        System.out.println("chapter跳转值编译后:"+URLDecoder.decode(chapter,"utf-8"));
        }catch (Exception e) {
            // TODO: handle exception
        }
        return "read";


都是乱码,
服务端getRequest().setAttribute("next", "这个可以有");
jsp就可以接收到中文,为什么呢?

------解决方案--------------------
你用的是什么服务器啊
在配置文件中也加上编码的配置试试
例:tomcat的server.xml中
 <Connector port="8080" protocol="HTTP/1.1" 
connectionTimeout="20000" 
redirectPort="8443" URIEncoding="UTF-8"/>