SSH+mysql中的乱码处理除了常用的新建数据库,数据库表时编码格式和java,jsp的编码格式一致外,还有:

1.在struts配置文件中配置全局的编码方式:

2.在web.xml添加对编码方式的拦截


struts2

org.apache.struts2.dispatcher.FilterDispatcher



struts.i18n.encoding
UTF-8




struts2
/*

3.在配置数据源时在数据库URL上加上编码格式:

jdbc:mysql://localhost:3306/photo?useUnicode=true&characterEncoding=UTF-8

注意:以上的配置方式放在.properties中是可以的但是如果放在.xml中是不行的会报错:

The reference to entity "characterEncoding" must end with the ';' delimiter.

需要修改成

jdbc:mysql://localhost:3306/photo?useUnicode=true&characterEncoding=UTF-8

下面给出xml中一些特殊符号的编码转换:

 < < 小于号
 > > 大于号
 & & and字符
 ' &#39; 单引号
 " " 双引号