web.xml中log4j属性文件的配置

 

<!-- web.xml-->

<?xml version="1.0" encoding="GB2312"?>
<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
 <context-param>
  <param-name>log4jConfigLocation</param-name>
  <param-value>/WEB-INF/classes/log4j.properties</param-value>
 </context-param>
 <!-- ContextConfigLocation -->
 <context-param>
     <param-name>contextConfigLocation</param-name>
     <param-value>/WEB-INF/spring-context/applicationContext.xml</param-value>
   </context-param>

 
 <filter>
        <filter-name>encodingFilter</filter-name>
        <filter-class>com.cn.commons.SetCharacterEncodingFilter</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>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
        <init-param>
         <param-name>config</param-name>
         <param-value>struts-default.xml,struts-plugin.xml,struts.xml,struts_books.xml</param-value>
        </init-param>
    </filter>
 

 <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
 </filter-mapping>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
  
 
 <!-- Listener contextConfigLocation -->
   <listener>
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
   </listener>
 <!-- Listener log4jConfigLocation -->
   <listener>
     <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
   </listener>

 
 <!-- The Welcome File List -->
 <welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
 </welcome-file-list>
</web-app>

选项C,springmvc.xmlSpring MVC的基本配置文件。在Spring MVC,我们需要使用一个配置文件配置Spring MVC框架和应用程序的相关属性,例如视图解析器、拦截器、处理器映射器等。这个配置文件通常被称为Spring MVC配置文件,一般命名为springmvc.xml。在该文件,我们可以使用SpringXML命名空间和标签来配置Spring MVC框架和应用程序。例如,以下是一个简单的Spring MVC配置文件: ``` <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <context:component-scan base-package="com.example"/> <mvc:annotation-driven/> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/views/"/> <property name="suffix" value=".jsp"/> </bean> </beans> ``` 在以上示例,我们使用了context命名空间来扫描指定包下的组件,使用mvc命名空间来启用Spring MVC注解支持,使用bean标签来定义一个视图解析器。因此,springmvc.xmlSpring MVC的基本配置文件。选项Aweb.xml文件是Servlet应用程序的部署描述文件,其可以配置Servlet、Filter、Listener等Web组件,但不是Spring MVC的基本配置文件;选项B的pom.xml文件是Maven项目的配置文件,其可以配置项目的依赖关系、插件、构建等信息,与Spring MVC无关;选项Dlog4j.properties文件Log4j日志框架的配置文件,与Spring MVC无关。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值