首页 > 代码库 > Servlet中通过过滤器实现统一的手动编码(解决中文乱码)

Servlet中通过过滤器实现统一的手动编码(解决中文乱码)

        <?xml version="1.0" encoding="UTF-8"?>          <web-app version="2.4" xmlns="http://<a href="http://www.mamicode.com/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://www.mamicode.com/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中通过过滤器实现统一的手动编码(解决中文乱码)