SpringMVC中文乱码
1:表单提交controller获得中文参数后乱码解决方案
注意: jsp页面编码设置为UTF-8
form表单提交方式为必须为post,get方式下面spring编码过滤器不起效果
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<form action="${ctx}/user/addUser" name="userForm" method="post">
修改web.xml,增加编码过滤器,如下(注意,需要设置forceEncoding参数值为true
<filter>
<filter-name>characterEncodingFilter</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>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
注意:
数据库编码是否支持中文
数据库表和表字段是否正确
在配置连接数据库的参数设置修改:
<property name="url" value="jdbc:mysql://192.168.5.36:3306/gjdw?useUnicode=true&characterEncoding=UTF-8&useOldAliasMetadataBehavior=true"/>