import org.apache.log4j.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Log4jinit extends HttpServlet {
public void init() {
String prefix = getServletContext().getRealPath("/");
String file = getInitParameter("log4j");
if (file != null) {
PropertyConfigurator.configure(prefix + file);
}
}
}
web.xml 的设置
<servlet>
<servlet-name>log4j-init</servlet-name>
<servlet-class>Log4j.Log4jinit</servlet-class>
<init-param>
<param-name>log4j</param-name>
<param-value>WEB-INF/log4j.properties</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Log4jinit extends HttpServlet {
public void init() {
String prefix = getServletContext().getRealPath("/");
String file = getInitParameter("log4j");
if (file != null) {
PropertyConfigurator.configure(prefix + file);
}
}
}
web.xml 的设置
<servlet>
<servlet-name>log4j-init</servlet-name>
<servlet-class>Log4j.Log4jinit</servlet-class>
<init-param>
<param-name>log4j</param-name>
<param-value>WEB-INF/log4j.properties</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
![emotion](http://www.matrix.org.cn/null/i/icon/emb2.gif)