1. 表单提交controller获得中文参数后乱码解决方案
将jsp页面的设置为utf-8字符编码集
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8" %>
form表单提交方式为必须为post,get方式下面spring编码过滤器不起效果。
<form:form modelAttribute="user" action="user/add" method="post" >
将以下配代码配置到web.xml中,增加编码过滤器。
<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>