SSH对于web.xml的配置

本文详细介绍了如何在项目中配置Struts2、Spring和log4j。包括注册Struts2的默认过滤器来处理所有用户请求;配置Spring的监听器以自动加载applicationContext.xml到Spring容器;设置log4j的日志管理和监听器。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、针对Struts2的配置

<filter>
<filter-name>SSH_1</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>SSH_1</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-class>
<url-pattern>

注册strtus2默认的过滤器,会过滤用户的请求。过滤哪些请求(过滤所有请求)
2、针对Spring的配置

<!-- Spring 监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

注册Spring默认的监听器,会自动转配applicationContext.xml配置信息到Spring容器(上下文)中。

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
<!-- <param-value>/WEB-INF/applicationContext.xml</param-value> -->
</context-param>

applicationContext.xml源码中放在/WEB-INF/applicationContext.xml,也可以放在其它位置
放在src下,则需要配置:classpath:applicationContext.xml。
3、针对日志管理log

<!--spring log4j监听器 -->
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<!--log4j配置文件加载 -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
<!--启动一个watchdog线程每1800秒扫描一下log4j配置文件的变化 -->
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>1800000</param-value>
</context-param>

Spring与log4j结合,具备打印日志的功能,首先配置Springlog4j监听器,然后加载log4j的配置文件(里面说明了要打印哪些内容以及打印日志存的目录),启动一个watchdog线程每1800秒扫描一下log4j配置文件的变化

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值