springmvc参数传递的几种乱码情况
1个回答
2018-07-12 · 国内最优秀java资源共享平台
关注
展开全部
@RequestParam 或者@PathVariable 等从URL或者Form Data 获取参数数据。
当其中有中文的时候,会发生了乱码。
1.方法一:修改Tomcat的server.xml
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
添加URIEncoding="utf-8"
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="utf-8"/>
2.方法二:手动更改
String name = new String(name.getBytes("ISO-8859-1"),"UTF-8");
其次POST方法
方法一:使用Spring的字符过滤器
配置在web.xml中:
<filter>
<filter-name>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>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
方法二:手动更改
当其中有中文的时候,会发生了乱码。
1.方法一:修改Tomcat的server.xml
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
添加URIEncoding="utf-8"
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="utf-8"/>
2.方法二:手动更改
String name = new String(name.getBytes("ISO-8859-1"),"UTF-8");
其次POST方法
方法一:使用Spring的字符过滤器
配置在web.xml中:
<filter>
<filter-name>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>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
方法二:手动更改
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询