ssm整合基本配置之web.xml

个人理解+参考总结,有错误请提出,谢谢!

1、加载spring配置文件:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext.xml
</param-value>
</context-param>

2、配置ContextLoaderListener:
   ContextLoaderListener的作用就是启动Web容器时,自动装配ApplicationContext的配置信息。
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
参考:http://wenwen.sogou.com/z/q740178826.htm

3、配置DispatcherServlet:
DispatcherServlet主要负责流程的控制。
<!-- spring mvc核心:分发servlet(就是控制流程) -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
    <!-- spring mvc的配置文件 -->
<init-param>
<param-name>contextConfigLocation</param-name>

<!-- 如是在WEB-INF文件夹下  如下这样写
  <param-value>/WEB-INF/springmvc.xml</param-value> -->

<!-- 如果实在src文件夹下  如下这样写
  <param-value>classpath:springMVC.xml</param-value>-->

</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
参考:http://jinnianshilongnian.iteye.com/blog/1602617

4、配置中文乱码处理CharacterEncodingFilter:
<filter>
<filter-name>encodingFilter</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>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

猜你喜欢

转载自592502042.iteye.com/blog/2405787