如题,能否给几个小例子。

解决方案 »

  1.   


    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
        <context-param>
            <param-name>log4jConfigLocation</param-name>
            <param-value>/WEB-INF/classes/log4j.properties</param-value>
        </context-param>
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/applicationContext.xml</param-value>
          </context-param>         <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</param-value>
            </init-param>
        </filter>    <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>
    /WEB-INF/classes/log4j.properties 配置网上一大堆。
      

  2.   

    进到MyEclipse文件夹下面
    搜索log4j
    就会有个文件夹log4j.properties
    放到src下面 就好了
      

  3.   

    http://hi.baidu.com/linyi12/blog/item/4014c0f2fe7d4712b07ec5a1.html
    自己去看吧!
      

  4.   

    context-param 和listener配置就好了,log4j的配置文件里面就是配置级别了,里面可以设置保存到某个文件,控制台,邮件等等