SSM整合之web.xml的相关配置
2018-02-16 09:02
351 查看
SSM整合之web.xml的相关配置
一、注册ServletContext监听器
<listener><listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
ps:为了在ServletContext初始化的时候创建Spring容器,就需要使用监听器,接口ServletContextListener对ServletContext进行监听,在web.xml中注册该监听器。Spring为该监听器接口定义了一个实现类,它完成了两个很重要的工作:创建容器对象,并将容器对象放入到了ServletContext的属性空间中,保证了整个应用中Spring容器的唯一性
二、指定Spring配置文件的位置及名称
<context-param><param-name>contextConfigLocation</param-name>
<param-value>classpath:resources/spring-*.xml</param-value>
</context-param>
ps:ContextLoaderListener在对Spring容器进行创建时,需要加载Spring配置文件。其默认的Spring配置文件位置与名称为:WEB-INF/applicationContext.xml。但一般会将该配置文件放置于项目的classpath下,即src下,所以需要在web.xml中对Spring配置文件的位置及名称进行指定。
三、注册字符集过滤器
<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>
ps:注册字符集过滤器,用于解决请求参数中携带中文时产生乱码问题
四、注册Springmvc中央调度器
<servlet><servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:resources/spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
ps:配置中央调度器时需要注意,Springmvc的配置文件名要与其他Spring配置文件名称格式相同。这样在上一步中指定所有Spring配置文件时,就将Springmvc的配置文件也包含进来,这样,就使得Spring容器在初始化时,将Springmvc配置文件中注册Bean也进行创建
c337
相关文章推荐
- SSM-4 web.xml 及相关spring配置文件
- ssm整合基本配置之web.xml
- 【SSM整合】-三框架整合xml文件结构及相应web.xml配置
- SSM(spring-springmvc-mybatis)整合开发xml配置文件内容springmvc-config.xml,application.xml,web.xml
- ssm框架整合配置---web.xml,傻傻分不清楚
- 最全三大框架整合(使用映射)——struts.xml和web.xml配置
- ssm的web.xml 配置信息
- ssm整合(基于xml配置方式)
- Listener监听器与web.xml相关配置
- ssm架構之web.xml配置
- SSH整合配置文件值web.xml
- SSM Spring +SpringMVC+Mybatis 整合配置 及pom.xml
- 搭建spring框架的时候,web.xml中的spring相关配置,可以不用配置ContextLoaderListener(即只配DispatcherServlet)吗?
- ssm项目之web.xml,spring,springmvc,mybatis配置
- shh整合后web.xml、spring配置文件和struts.xml的内容
- ssm框架下web项目,web.xml配置文件的作用(详解)
- Maven整合SSM框架相关的配置文件
- shh整合后web.xml、spring配置文件和struts.xml的内容
- SSM框架整合方式(二):XML配置文件代码
- SpringMVC与Spring整合,配置web.xml