您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
5-ssm整合-原始整合方式web.xml配置文件内容填充
发布时间:2025-02-08 16:00:10编辑:雪饮阅读()
-
接续上篇,这次来配置spring监听器,用于web容器启动时加载spring配置文件;
配置springmvc的前端控制器,用于加载springmvc的配置文件;配置乱码过滤器用来解决一些乱码问题。这些配置都将配置于如D:\os\SpringWebApp\SpringProject2Module10SSM\src\main\webapp\WEB-INF\web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<!--spring 监听器-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!--springmvc的前端控制器-->
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
<!--
加载顺序
当值为0或者大于0时,代表容器启动时加载该servlet。正数的值越小,
启动时加载该servlet的优先级越高。如果为负数,则容器启动时不会加载该servlet,只有该servlet被选择时才会加载。
-->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!--乱码过滤器-->
<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>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
关键字词:ssm,原始,方式,环境,搭建,整合,填充,spring,mvc,web.xml