[b]1. Spring在web.xml中设置过滤器[/b]
[b]2. 在tomcat的server.xml中设置utf-8字符集[/b]
[b]3. 在spring-mvc的@ResponseBody出现乱码问题, 解决如下[/b]
[b][color=red]PS: messageAdapter必须在<mvc:annotation-driven /> 之前!!!![/color][/b]
<filter>
<filter-name>Set Character Encoding</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>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
[b]2. 在tomcat的server.xml中设置utf-8字符集[/b]
<Connector port="8080"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000" useBodyEncodingForURI="true"
disableUploadTimeout="true" URIEncoding="UTF-8"/>
[b]3. 在spring-mvc的@ResponseBody出现乱码问题, 解决如下[/b]
<bean id="messageAdapter" class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>
</list>
</property>
</bean>
<mvc:annotation-driven />
[b][color=red]PS: messageAdapter必须在<mvc:annotation-driven /> 之前!!!![/color][/b]