1. web.xml中配置了CharacterEncodingFilter,配置这个是拦截所有的资源并设置好编号格式。
encoding设置成utf-8就相当于request.setCharacterEncoding("UTF-8");
foreEncoding设置成true就相当于response.setCharacterEncoding("UTF-8");
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
< 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 >
< init-param >
< param-name >forceEncoding</ param-name >
< param-value >true</ param-value >
</ init-param >
</ filter >
< filter-mapping >
< filter-name >CharacterEncodingFilter</ filter-name >
< url-pattern >/*</ url-pattern >
</ filter-mapping >
|
2. web.xml配置DispatcherServlet,配置这个是拦截所有请求,都交给springmvc转发
拦截所有的请求,并加载所有的ssm配置文件(路径为classpath:---)
1
2
3
4
5
6
7
8
9
10
11
12
|
< servlet >
< servlet-name >mvc-dispatcher</ servlet-name >
< servlet-class >org.springframework.web.servlet.DispatcherServlet</ servlet-class >
< init-param >
< param-name >contextConfigLocation</ param-name >
< param-value >classpath:spring-*.xml</ param-value >
</ init-param >
</ servlet >
< servlet-mapping >
< servlet-name >mvc-dispatcher</ servlet-name >
< url-pattern >/</ url-pattern >
</ servlet-mapping >
|
以上这篇ssm框架下web项目,web.xml配置文件的作用(详解)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:http://www.cnblogs.com/winv758241/p/6889383.html