对于使用了SSH造成的中文乱码问题,4大解决方法

  1. struts2.xml 中添加 <constant name="struts.i18n.encoding" value="UTF-8"></constant>

  2. jsp页面加入 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>

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

                            <filter-mapping>

                                     <filter-name>encodingFilter</filter-name>

                                     <url-pattern>/*</url-pattern>

                            </filter-mapping>

4. 修改tomcat /conf/server.xml中的<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"><Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8"  useBodyEncodingForURI="true"  />

你可能感兴趣的:(中文乱码)