I’m writing my first Java EE application, using EJBs, Servlet, JSPs and the likes.
I’m using JBOSS 4.2 AS and Eclipse as and IDE, including tasks like starting and stopping the server.
What I can’t understand is that while logging instructions inside a jsp, like:
<% System.out.println("Log this!"); %>
log as expected, both in Eclipse console and in $SERVER_HOME/server/default/log/server.log, any kind of logging instruction I’ve tried inside a servlet fails.
Here’s the code from the jsp that calls the servlet:
<form action="MyServlet" method="POST" accept-charset="utf-8">
<input type="text" name="id" value="" id="id">
<input type="submit" value="Go →">
</form>
And of course the servlet itslef:
public class MyServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public MyServlet() {
super();
System.out.println("Hi, I'm your servlet's constructor");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.err.println("Hi, this is your servlet on system.err");
System.out.println("Hi, this is your servlet on system.out");
System.out.println(request);
ServletContext sc = getServletContext();
sc.log("Hi, this is your servlet on servlet context!");
}
}
Am I missing something obvious? Doing everything wrong, or just looking in the wrong place?
If you don’t see anything being written to stdout/stderr, then this just means that the servlet is actually not been executed. That can have lot of trivial causes. Is the Servlet in the classpath? Is the Servlet definied in
web.xmlor annotated with@WebServlet? Is theurl-patterncorrect? Does the request URL cover it? What does the Eclipse debugger say? What does the appserver’s own logs say?By the way, this isn’t actually logging. This is just plain writing to stdout/stderr. Logging is more than that.