Logging strings or exceptions to the JSP engine

The HttpServlet class extends from the GenericServlet superclass. This latter has two useful log methods:

   log(String)
   log(String, Throwable)

You can use these methods to write messages to the logs of your JSP/Servlet engine (they implement it all differently).
For example, the following JSP

<%
   log("Check your log, eg catalina_log...");
   log("An exception", new Exception());
%>
Lines logged!

logged the following in my current log file catalina_log.2003-04-01.txt:

2003-04-01 17:45:47 jsp: Check your log, eg catalina_log...
2003-04-01 17:45:47 jsp: An exception
java.lang.Exception
        at org.apache.jsp.logtest$jsp._jspService(logtest$jsp.java:56)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:201)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:381)
. . .

Look at the Tomcat category or documentation to see how you can change the file you want to log to.