关于struts.i18n.encoding的疑问
大家现在都清楚了,struts.i18n.encoding既应用于请求流也应用于返回流。但通过对源码org.apache.struts2.dispatcher.FilterDispatcher的研究发现好像只对requst指定了encode啊?大家请看源码
Java代码
1. public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws
IOException,
ServletException {
2. HttpServletRequest request = (HttpServletRequest) req;
3. HttpServletResponse response = (HttpServletResponse) res;
4. ServletContext servletContext = getServletContext();
5. String timerKey = "FilterDispatcher_doFilter: ";
6. try {
7. UtilTimerStack.push(timerKey);
8. request = prepareDispatcherAndWrapRequest(request, response);//这里是重点
9. //这里省略后面的代码
10. } finally {
11. try {
12. ActionContextCleanUp.cleanUp(req);
13. } finally {
14. UtilTimerStack.pop(timerKey);
15. }
16. }
17. }
18. }
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
ServletContext servletContext = getServletContext();
String timerKey = "FilterDispatcher_doFilter: ";
try {
UtilTimerStack.push(timerKey);
request = prepareDispatcherAndWrapRequest(request, response);//这里是重点
//这里省略后面的代码
} finally {
try {
ActionContextCleanUp.cleanUp(req);
} finally {
UtilTimerStack.pop(timerKey);
}
}
}
}
prepareDispatcherAndWrapRequest
Java代码
1. protected HttpServletRequest prepareDispatcherAndWrapRequest(HttpServletRequest request, HttpServletResponse response) throws
2. ServletException {
3. Dispatcher du = Dispatcher.getInstance();
4. if (du == null) {
5. Dispatcher.setInstance(dispatcher);
6. dispatcher.prepare(request, response);//这里是重点
7. } else {
8. dispatcher = du;
9. }
10. //省略了一些代码
11. return request;
12. }
protected HttpServletRequest prepareDispatcherAndWrapRequest(HttpServletRequest request, HttpServletResponse response) throws
ServletException {
Dispatcher du = Dispatcher.getInstance();
if (du == null) {
Dispatcher.setInstance(dispatcher);
dispatcher.prepare(request, response);//这里是重点
} else {
dispatcher = du;
}
//省略了一些代码
return request;
}
prepare
Java代码
1. public void prepare(HttpServletRequest request, HttpServletResponse response) {
2. String encoding = null;
3. if (defaultEncoding != null) {
4. encoding = defaultEncoding;
5. }
6. //省略了一些代码
7. if (encoding != null) {