Forums Register Login

How to Use ServletContext.log()

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
You got that error because getServletConfig() is an instance method (in GenericServlet).
The log method has two forms
log( String msg )
log( String msg, Throwable t )
You got the order of parameters backwards.
Bill
Whoever got anywhere by being normal? Just ask this exceptional tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 4304 times.
Similar Threads
code on pg 675
log messages
Writing to log files from jsp page
Tomcat 5.5 and context.log
Is Exception handling there
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 05:42:55.