如果过滤器使用的是gb2312编码则没问题,读取正常。为了配合前台html页必须使用utf-8.
直接在数据库里添加中文时正常显示,jsp正常读取。
通过jsp页插入中文数据则在数据库里是乱码,读出也是乱码
数据库 乱码 jsp utf-8
------解决方案--------------------
Struts.xml:<constant name="struts.i18n.encoding" value="UTF-8" />
web.xml:
<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>
jsp:<%@ page language="java" contentType="text/html;
charset=UTF-8" pageEncoding="UTF-8"%>
tomcat:<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8" />
其他地方可以设的都设成同一编码