request.setCharacterEncoding("UTF-8");
另外查了下資料,也有幾個地方要注意
1. 在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>
2. JSP中要加入
<%@page contentType="text/html" pageEncoding="UTF-8"%>
3. server.xml中的conntector要加入useBodyEncodingForURI
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" useBodyEncodingForURI="true"/>