spring mvc 表单提交 乱码

1。在web.xml添加过滤器:

<filter>
<filter-name>SpringCharacterEncoding</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>SpringCharacterEncoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

2.spring-mvc 配置文件,配置自动扫描时:

    <mvc:annotation-driven>
<mvc:message-converters register-defaults="true">
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
<value>text/json;charset=UTF-8</value>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>

3.post提交就没问题,而get可能还需要在方法上@RequestMapping注解添加produces参数

@RequestMapping(value="/selectPlaceListMap",produces = "text/html;charset=UTF-8")

4.以上不行,就修改eclipse自身配置的servers底下的server.xml

文件spring mvc 表单提交 乱码

修改:

<Connector URIEncoding="UTF-8" connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>

没有则添加,实际运行环境更改tomcat的server.xml即可。

上一篇:解决Centos关闭You have new mail in /var/spool/mail/root提示(转)


下一篇:spring mvc 返回xml格式数据