log4j.properties
在WEB-INF/classes下

解决方案 »

  1.   

    to dafei0320(大飞) :
    我就是放在那里的,还是不行。
    是不是还需要配置其他的文件的?比如:web.xml
      

  2.   

    放在WEB-INF下
    要web.xml中配置一下,放在启动servlet的初始参数中
      

  3.   

    szpqq(Gavin) :怎么启动servlet的初始参数?你能把代码贴出来吗?谢谢了
      

  4.   

    你的log.properties文件要放在"user.dir"下面。一般是tomcat_home/bin目录。
    如果不是的话,你可这样取得:
    String path = System.getProperty("user.dir");
    System.out.println(path);把你的log.properties文件放到输出的路径就行了。
      

  5.   

    最简单的Log4j初始化public class Log4jInit extends HttpServlet {    public void init() {

            String prefix = getServletContext().getRealPath("/");
            String file   = getInitParameter("log4j");        System.out.println("................log4j start");        if(file != null) {
                PropertyConfigurator.configure(prefix+file);
            }
        }

        public void doGet(
            HttpServletRequest req
            , HttpServletResponse res)
            throws ServletException
            , IOException {
        }
    }web.xml
    <servlet>
        <servlet-name>log4j-init</servlet-name>
        <servlet-class>kintaisystem.Log4jInit</servlet-class>
        <init-param>
            <param-name>log4j</param-name>
            <param-value>WEB-INF/properties/log4j.properties</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
      

  6.   

    Tasia(这里是CSDN吗?):太厉害了,用你这个方法一试,果然就可以!非常感谢,马上送份!!