JSP页面上的中文数据传到后台乱码处理汇总
2016-08-19 10:55
337 查看
SpringMVC框架下的web项目,JSP页面上的中文传到后台乱码的情况下,这儿汇总了五种可能出现乱码解决的情况,如果你的项目中也出现了乱码,可以尝试从以下方面进行解决(使用UTF-8的编码方式)。
1、web.xml中配置编码过滤器
2、JS页面上设置pageEncoding
3、如果使用的是Ajax进行数据传输出现乱码,对Ajax传输的数据设置编码contentType:"application/x-www-form-urlencoded; charset=utf-8":
4、使用tomcat服务器的情况下,上面几点都设置好了还是乱码就去查看tomcat配置文件web.xml(路径:tomcat/conf/web.xml),设置tomcat的编码过滤器为UTF-8,配置位置如下:
5、tomecat服务器的配置文件中,设置编码过滤器前面有一行注释,parameters in a POST request,从我遇到的实际情况来看确实是这样的,这个过滤器只对post方式发送的请求中的数据有效,而对get请求中的参数是无效的。
get请求方式发送的中文数据(url拼接)在前面都设置好后还会乱码的话,进入tomcat的配置文件server.xml(路径:tomcat/conf/server.xml),给
添加URI的编码属性:URIEncoding="UTF-8"即改为:
目前我所遇到的乱码情况用这几种方式都能解决,如果还有其他情况欢迎告知补充。
1、web.xml中配置编码过滤器
<filter> <filter-name>SetCharacterEncoding</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>SetCharacterEncoding</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
2、JS页面上设置pageEncoding
<a target=_blank href="mailto:%@page language='java' import='java.util.*' pageEncoding='UTF-8'%">%@page language="java" import="java.util.*" pageEncoding="UTF-8"%</a>
3、如果使用的是Ajax进行数据传输出现乱码,对Ajax传输的数据设置编码contentType:"application/x-www-form-urlencoded; charset=utf-8":
$.ajax({ url : url, type : "POST", dataType : "json", async : false, contentType:"application/x-www-form-urlencoded; charset=utf-8", data : $("#communication_frm").serialize(), success : function(result) {}, error : function() {} });
4、使用tomcat服务器的情况下,上面几点都设置好了还是乱码就去查看tomcat配置文件web.xml(路径:tomcat/conf/web.xml),设置tomcat的编码过滤器为UTF-8,配置位置如下:
<!-- A filter that sets character encoding that is used to decode --> <!-- parameters in a POST request --> <filter> <filter-name>setCharacterEncodingFilter</filter-name> <filter-class>org.apache.catalina.filters.SetCharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> </filter>
5、tomecat服务器的配置文件中,设置编码过滤器前面有一行注释,parameters in a POST request,从我遇到的实际情况来看确实是这样的,这个过滤器只对post方式发送的请求中的数据有效,而对get请求中的参数是无效的。
get请求方式发送的中文数据(url拼接)在前面都设置好后还会乱码的话,进入tomcat的配置文件server.xml(路径:tomcat/conf/server.xml),给
<Connector executor="tomcatThreadPool" port="1522" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
添加URI的编码属性:URIEncoding="UTF-8"即改为:
<Connector executor="tomcatThreadPool" port="1522" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8"/>
目前我所遇到的乱码情况用这几种方式都能解决,如果还有其他情况欢迎告知补充。
相关文章推荐
- 前台页面传到后台的中文数据出现乱码问题
- jsp 页面中文 传到后台 乱码问题解决
- 关于jsp页面上中文数据传递到后台成乱码的解决方法
- 解决从JSP页面获取后台数据中文乱码问题?
- jsp数据传递到后台为中文乱码的解决方法
- post方式与get方式提交到Jsp页面中文乱码的处理
- jsp页面中中文乱码的处理措施
- 页面与后台交互中文乱码处理总结
- jsp 页面传值 到后台 中文乱码解决方法
- 后台out.println向jsp页面推送中文时乱码
- 从页面向后台(struts)post数据,中文乱码问题解决
- struts1.x数据从前台jsp到后台actionform中文乱码
- jsp 页面传值 到后台 中文乱码解决方法
- js操作从后台传到jsp页面上的list数据
- jsp页面转后台,出现中文乱码
- jsp的表单数据提交,中文出现乱码的处理
- jsp页面利用get方式提交到后台的数据为乱码格式的解决办法
- JSP get 请求 Tomcat 服务器 插入数据到数据库中文乱码处理
- JSP页面显示中文乱码解决方法汇总
- SSM框架Jsp页面POST提交的中文数据保存到数据库变成乱码问题的分析