1.编写相对的监听器 public class log4jlistener implements ServletContextListener { public static final String log4jdirkey = "log4jdir"; public void contextDestroyed(ServletContextEvent servletcontextevent) { System.getProperties().remove(log4jdirkey); } public void contextInitialized(ServletContextEvent servletcontextevent) { String log4jdir = servletcontextevent.getServletContext().getRealPath("/"); //System.out.println("log4jdir:"+log4jdir); System.setProperty(log4jdirkey, log4jdir); } } 2.在web.xml中配置 <listener> <listener-class>xxx.xxx.log4jlistener</listener-class> </listener> 3.log4j配置文件中配置 log4j.appender.A1.File=${log4jdir}/WEB-INF/logs/app1.log 来解决。 来源:http://hbiao68.iteye.com/blog...
1.编写相对的监听器
2.在web.xml中配置
3.log4j配置文件中配置