tomcat下通过初始化servlet来配置log4j的问题
任叔 2003-04-10 01:34:49 目前,启动tomcat时,信息如下:
==================================================================
Starting service Tomcat-Standalone
Apache Tomcat/4.0.4
ERROR reading java.io.ByteArrayInputStream@38bef7
At Line 13 /web-app/servlet/
Starting service Tomcat-Apache
Apache Tomcat/4.0.4
==================================================================
请问这可能是什么问题引起的?或者有什么其它办法配置log4j使我可以在web application项目的javabean及jsp页面中调用log4j
详细情况说明:
我的虚拟目录路径为e:\tomcat\webapps\dz2, dz2下的web.xml内容如下:
===============================================================
<?xml version="1.0" encoding="ISO-8859-1"?>
<!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>
<servlet>
<servlet-name>dzlog4jinit</servlet-name>
<servlet-class>org.javaresearch.log4j.dzlog4jinit</servlet-class>
<init-param>
<param-name>log4jconfig</param-name>
<param-value>/log4j.properties</param-value>
</init-param>
<!-- Load this servlet at server startup time -->
<load-on-startup>1</load-on-startup>
</servlet>
</web-app>
==================================================================
e:\tomcat\webapps\dz2存放log4j.properties文件。
e:\tomcat\webapps\dz2\web-inf\classes\org\javaresearch\log4j下存放dzlog4jinit.class和dzlog4jinit.java文件,dzlog4jinit.java文件内容如下:
==================================================================
package org.javaresearch.log4j ;
import java.io.* ;
import javax.servlet.* ;
import javax.servlet.http.*;
import org.apache.log4j.* ;
public class dzlog4jinit extends HttpServlet
{
public void init () throws ServletException
{
String prefix = getServletContext ().getRealPath ( "/" ) ;
String file = getServletConfig ().getInitParameter ( "log4jconfig" ) ;
// 从Servlet参数读取log4j的配置文件
if ( file != null )
{
PropertyConfigurator.configure ( prefix + file ) ;
}
}
public void doGet ( HttpServletRequest request , HttpServletResponse response ) throws
IOException , ServletException
{}
public void doPost ( HttpServletRequest request , HttpServletResponse response ) throws
IOException , ServletException
{}
}
==================================================================