springmvc(十一)post乱码
2016-02-01 16:59
501 查看
在web.xml添加post乱码filter
在web.xml中加入:
以上可以解决post请求乱码问题。
对于get请求中文参数出现乱码解决方法有两个:
修改tomcat配置文件添加编码与工程编码一致,如下:
另外一种方法对参数进行重新编码:
ISO8859-1是tomcat默认编码,需要将tomcat编码后的内容按utf-8编码
在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> </filter> <filter-mapping> <filter-name>CharacterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
以上可以解决post请求乱码问题。
对于get请求中文参数出现乱码解决方法有两个:
修改tomcat配置文件添加编码与工程编码一致,如下:
<Connector URIEncoding="utf-8" connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
另外一种方法对参数进行重新编码:
String userName = new String(request.getParamter("userName").getBytes("ISO8859-1"),"utf-8")
ISO8859-1是tomcat默认编码,需要将tomcat编码后的内容按utf-8编码
相关文章推荐
- springmvc(十)springmvc和struts2的区别
- JDK的bin目录下那些常见工具使用集锦
- Java动态代理的实现机制
- 【java基础】Minor GC、Major GC和Full GC之间的区别
- Struts2--标签
- JAVA使用commos-fileupload实现文件上传与下载实例解析
- Java 反射使用
- Can I create an array whose component type is a concrete parameterized type? 我可以创建一个泛型数组嘛?
- Spring(AbstractRoutingDataSource)实现动态数据源切换--转载
- java获取properties配置文件中的信息
- Spring配置文件详解
- Java Annotation 及几个常用开源项目注解原理简析
- ubuntu12.04 安装配置jdk1.7
- ubuntu12.04 安装配置jdk1.7
- Java中怎么将数据封装成XML格式
- java泛型
- java_AES加密解密文件以及字符串
- Java 多态性 理解
- Spring 4.2框架中注释驱动的事件监听器详解
- Java泛型