I need to log error messages to the tomcat log. Someone suggested using the ServletContext.log(). I tried this and I am getting the following error. "Non-static method log() cannot be reference from static context" What am I doing wrong. Could you give me a code example? Thanks, Beth
hi Beth, u can view the servlet api at, JakartaTomcat Page log() is a method in GenericServlet Class and so HttpServlet has it and as a result our servlets that extends HttpServlet also has it. so we can just call log() method in our servlet without referring to any other class. log() isn't a static method. it's an instance method. regards maulin
Here is what I tried: At the top of the bean I have: import javax.servlet.http.*; //already had this //added the 3 below to try to get this to work. import javax.servlet.http.HttpServlet; import javax.servlet.*; import javax.servlet.ServletContext; I tried: ServletConfig sConf = Servlet.getServletConfig(); ServletContext SC = sConf.getServletContext(); SC.log(e,sErrorString); Error: "non-static method getServletConfig() cannot be referenced from a static context ServletConfig sConf = Servlet.getServletConfig();" I also tried: log(e, sErrorString); Error: "cannot resolve symbol symbol : method log (java.lang.Exception,java.lang.String) log(e, sErrorString);" Help, What am I doing wrong? Thanks, Beth
You got that error because getServletConfig() is an instance method (in GenericServlet). The log method has two forms log( Stringmsg ) log( String msg, Throwable t ) You got the order of parameters backwards. Bill