Servlet中通过过滤器实现统一的手动编码(解决中文乱码)
Posted Zhan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Servlet中通过过滤器实现统一的手动编码(解决中文乱码)相关的知识,希望对你有一定的参考价值。
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://<a href="http://lib.csdn.net/base/javaee" class=‘replace_word‘ title="Java EE知识库" target=‘_blank‘ style=‘color:#df3434; font-weight:bold;‘>Java</a>.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <servlet> <servlet-name>test</servlet-name> <servlet-class>selfimpr.web.encoding.test.TestServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>test</servlet-name> <url-pattern>/servlet/test</url-pattern> </servlet-mapping> <filter> <filter-name>parameterEncoding</filter-name> <filter-class>selfimpr.web.encoding.test.ParameterEncodingFilter</filter-class> <init-param> <param-name>oldEncoding</param-name> <param-value>ISO8859-1</param-value> </init-param> <init-param> <param-name>newEncoding</param-name> <param-value>GBK</param-value> </init-param> </filter> <filter-mapping> <filter-name>parameterEncoding</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://<a href="http://lib.csdn.net/base/javaee" class=‘replace_word‘ title="Java EE知识库" target=‘_blank‘ style=‘color:#df3434; font-weight:bold;‘>Java</a>.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <servlet> <servlet-name>test</servlet-name> <servlet-class>selfimpr.web.encoding.test.TestServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>test</servlet-name> <url-pattern>/servlet/test</url-pattern> </servlet-mapping> <filter> <filter-name>parameterEncoding</filter-name> <filter-class>selfimpr.web.encoding.test.ParameterEncodingFilter</filter-class> <init-param> <param-name>oldEncoding</param-name> <param-value>ISO8859-1</param-value> </init-param> <init-param> <param-name>newEncoding</param-name> <param-value>GBK</param-value> </init-param> </filter> <filter-mapping> <filter-name>parameterEncoding</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
以上是关于Servlet中通过过滤器实现统一的手动编码(解决中文乱码)的主要内容,如果未能解决你的问题,请参考以下文章