ssm开发关于web.xml配置

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app version="3.0" 
 3     xmlns="http://java.sun.com/xml/ns/javaee" 
 4     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 5     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
 6     http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
 7   <display-name>Archetype Created Web Application</display-name>
 8   <welcome-file-list>
 9     <welcome-file>/WEB-INF/pages/index.jsp</welcome-file>
10   </welcome-file-list>
11   <!-- 配置监听spring-->
12   <listener>
13       <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
14   </listener>
15   <!-- 指定spring bean 的配置文件所在目录 -->
16   <context-param>
17       <param-name>contextConfigLocation</param-name>
18       <param-value>classpath:applicationContext-*.xml</param-value>
19   </context-param>
20   
21   <!-- 配置spring字符编码为utf-8 -->
22   <filter>
23       <filter-name>encodingFilter</filter-name>
24       <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
25       <init-param>
26           <param-name>encoding</param-name>
27           <param-value>UTF-8</param-value>
28       </init-param>
29       <init-param>
30           <param-name>forceEncoding</param-name>
31           <param-value>true</param-value>
32       </init-param>
33   </filter>
34   <filter-mapping>
35       <filter-name>encodingFilter</filter-name>
36       <url-pattern>/*</url-pattern>
37   </filter-mapping>
38   
39   <!-- springMVC的配置 -->
40   <servlet>
41       <servlet-name>spring</servlet-name>
42       <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
43       <init-param>
44           <param-name>contextConfigLocation</param-name>
45           <param-value>classpath:spring-servlet.xml</param-value>
46       </init-param>
47       <load-on-startup>1</load-on-startup>
48   </servlet>
49   <servlet-mapping>
50       <servlet-name>spring</servlet-name>
51       <url-pattern>/</url-pattern>
52   </servlet-mapping>
53  
54   
55   
56   <!-- log4j配置 -->
57   <context-param>
58       <param-name>log4jConfigLocation</param-name>
59       <param-value>classpath:log4j.properties</param-value>
60   </context-param>
61   <context-param>
62       <param-name>webAppRootKey</param-name>
63       <param-value>SLSaleSystem.root</param-value>
64   </context-param>
65   <!-- spring加载log4j的监听 -->
66   <listener>
67       <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
68   </listener>
69 </web-app>

 

转载于:https://www.cnblogs.com/wiseroll/p/7258882.html

SSM(Spring + SpringMVC + MyBatis)是一个基于Spring、Spring MVC和MyBatis的轻量级Java Web开发框架组合,它们在web应用中通常会使用`web.xml`文件来配置初始化参数和控制器映射等信息。`web.xml`是Servlet规范的一部分,主要负责定义应用程序的全局行为。 在SSM项目中,`web.xml`的主要配置包括以下几个部分: 1. **Servlet和Filter配置**:这里会定义Spring MVC的DispatcherServlet,以及可能使用的过滤器(如字符编码过滤器、日志记录过滤器等)。 ```xml <web-app> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring-mvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> ... <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> ... </web-app> ``` 2. **Multipart Config**:如果项目需要处理文件上传,会配置MultipartResolver。 ```xml <multipart-config> <location>/WEB-INF/upload</location> <max-file-size>10MB</max-file-size> <max-request-size>100MB</max-request-size> </multipart-config> ``` 3. **ContextLoaderListener**:用于加载Spring的上下文。 ```xml <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> ``` 4. **Controller映射**:通过`<url-pattern>`标签指定请求URL和哪个控制器方法关联。 ```xml <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值