Spring MVC中文乱码解决方案
2016-03-13 00:00
459 查看
摘要: 提供了两种解决方式,分别是get中文乱摸和post中文乱码
web项目和SpringMvc集成的时候出现中文乱码
post:jsp页面
java后台:
出现乱码:æ¯å¦æçå
解决方式:在web.xml文件里面添加filter,注意这种方式只能解决post方式的乱码
post:乱码问题解决
------------------------------------------------------------------------------------------------------------------
get:乱码
ajax,a标签,form,浏览器地址栏输入的参数都有可能出现get方式的请求
这种方式在和具体服务器的配置有关
比如tomcat解决方式
在server.xml里面
将
修改成
web项目和SpringMvc集成的时候出现中文乱码
post:jsp页面
<body> ${username} <form action="myController" method="post"> <input name="username" type="text" > <input type="submit" value="提交" > </form> </body>
java后台:
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { String username = request.getParameter("username"); System.out.println(username); ModelAndView model = new ModelAndView(); model.addObject("username", username); System.out.println(username); return model; }
出现乱码:æ¯å¦æçå
解决方式:在web.xml文件里面添加filter,注意这种方式只能解决post方式的乱码
<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> </filter> <filter-mapping> <filter-name>characterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
post:乱码问题解决
------------------------------------------------------------------------------------------------------------------
get:乱码
ajax,a标签,form,浏览器地址栏输入的参数都有可能出现get方式的请求
这种方式在和具体服务器的配置有关
比如tomcat解决方式
在server.xml里面
将
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" />
修改成
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8"/>
相关文章推荐
- GET和post取值限制区别分析
- 深入C#中get与set的详解
- POST与GET方法的区别简要分析
- VB使用XMLHTTP实现Post与Get的方法
- 分享下GET和POST的真正区别
- ASP.NET的HtmlForm控件学习及Post与Get的区别概述
- asp教程中get post提交表单有5点区别
- 区分ASP.NET中get方法和post方法
- php下通过POST还是GET来传值
- jQuery调用AJAX时Get和post公用的乱码解决方法实例说明
- ajax请求get与post的区别总结
- Jquery AJAX POST与GET之间的区别
- jquery中常用的SET和GET
- jQuery中get和post方法传值测试及注意事项
- ajax请求post和get的区别以及get post的选择
- jQuery中ajax - get() 方法实例详解
- JSP、Servlet中get请求和post请求的区别总结
- 深入理解curl类,可用于模拟get,post和curl下载
- jq的get传参数在utf-8中乱码问题的解决php版
- GET 方式提交的含有特殊字符的参数