Tomcat和Weblogic下ajax或get中文乱码

此种方法保证在Tomcat和Weblogic下都不会产生乱码

1、 <Connector port="8080" protocol="HTTP/1.1"
                       connectionTimeout="20000"
                       redirectPort="8443" URIEncoding="UTF-8"/>

     更改tomcat编码,tomcat默认为iso-8859-1

2、web.xml 配置spring 编码

 <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>

3、JSP

    将参数encodeURI(url)

4、action:

 companyName= java.net.URLDecoder.decode(request.getParameter("companyName"),"UTF-8");
 或者直接获取
 companyName=request.getParameter("companyName");

这样部署到weblogic下不会乱码,也不用在filter里面去设置编码

发布到weblogic将spring配置文件放到/WEB-INF/下,不然会找不到

posted @ 2011-11-16 15:17  七郎  Views(3368)  Comments(0Edit  收藏  举报