JavaWeb浏览器传值乱码
Posted tjc123
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaWeb浏览器传值乱码相关的知识,希望对你有一定的参考价值。
使用tomcat乱码
1.在tomcat的conf/server.xml中的connector,添加URIEncoding=utf-8;
<Connector port="8081" protocol="HTTP/1.1" connectionTimeout="200000" URIEncoding="UTF-8"/>
2. 在tomcat的bin/catalina.sh中加JAVA_OPTS
JAVA_OPTS="-Xms1024m -Xmm4096m -Dfile.encoding=utf-8"
CATALINA_OPTS="-Dfile.encoding=utf-8"
3.添加 encoding filter,使得encoding filter就在servlet下面;中间不能有其他filter.
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-parttern>*.do</url-parttern>
</servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-parttern>/web/*</url-parttern>
</servlet-mapping>
<filter>
<filter-name>CharacterEncoding</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>
<filter-mapping>
<filter-name>CharacterEncoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
以上是关于JavaWeb浏览器传值乱码的主要内容,如果未能解决你的问题,请参考以下文章