request.getCharacterEncoding() 的返回值为什么会是null
来源:互联网 发布:蘑菇软件是什么 编辑:程序博客网 时间:2024/05/16 18:05
在webxml 中用spring提供的过滤器
1
2
3
4
5
6
7
8
9
10
<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>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
以下是类的源码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public
class
CharacterEncodingFilter
extends
OncePerRequestFilter {
private
String encoding;
private
boolean
forceEncoding =
false
;
public
void
setEncoding(String encoding) {
this
.encoding = encoding;
}
public
void
setForceEncoding(
boolean
forceEncoding) {
this
.forceEncoding = forceEncoding;
}
@Override
protected
void
doFilterInternal(
HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws
ServletException, IOException {
//request.getCharacterEncoding() 返回值默认是null,但默认编码格式是ISO-8859-1,如果设置forceEncoding=false,假设存在上一级过滤器更改了request的编码,则使用request的编码
if
(
this
.encoding !=
null
&& (
this
.forceEncoding || request.getCharacterEncoding() ==
null
)) {
request.setCharacterEncoding(
this
.encoding);
if
(
this
.forceEncoding) {
response.setCharacterEncoding(
this
.encoding);
}
}
filterChain.doFilter(request, response);
}
0 0
- request.getCharacterEncoding() 的返回值为什么会是null
- 为什么findViewById会返回null
- 求救:为什么调用System.console()方法返回的是null?
- multipart/form-data 类型的form使用request.getParameter()会返回null
- 不要被request.getCharacterEncoding()误导
- 为什么strcpy的返回值是char* ?
- 为什么strcpy的返回值是char* ?
- 为什么RegExp.prototype.exec()的返回值会变化
- 为什么JavaScript里面typeof(null)的值是"object"?
- AfxGetMainWnd()为什么返回NULL
- 为什么返回值是ostream&
- 为什么在mysql_query()返回成功后,mysql_store_result()有时会返回NULL
- 汉字的ASC值为什么会是负数
- i = i++为什么会是i原来的值??
- request,response传入线程值会变为null
- 为什么request.getParameterValues("XXX")接收select数组的值为null
- mysql_insert_id 为什么会返回空值
- Cursor返回是null
- spring配置datasource的4种方式
- 遇到一个很有趣的问题,while(ture)或者for循环出现异常,继续执行还是跳出异常
- 在Ubuntu上创建Git仓库并上传到GitHub
- js 浅拷贝与深拷贝
- Spring中bean的init和destroy方法讲解
- request.getCharacterEncoding() 的返回值为什么会是null
- MapReduce-------------Win7下使用Eclipse玩转Linux端的MapReduce
- 【iOS界面开发】iOS事件派发机制
- C3P0连接池配置
- MyBatis使用总结和整合Spring
- 1小时搭建个人网站:购买虚拟主机,购买域名,绑定IP和申请SSL证书实现https
- SNNU2017校赛(部分)题解
- Spring和Mybatis整合时无法读取properties的处理方案
- Codeforces 796C Bank Hacking 贪心+规律