0

I have seen in some servlet programs, System.out.println() statements. Do they work? If so where are they printed? I have checked the Web console in the browser. But I couldn't see it?

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class MyServlet extends HttpServlet
{
    public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
    {
        System.out.println("This is in System.out.println()");
    }
}

Because this program is not executed in command prompt, where will the output be printed? Is there any console in the browser that can print this?

JavaTechnical
  • 8,846
  • 8
  • 61
  • 97

3 Answers3

1

I think this is a duplicate question, but, you typically only use System.out.println() in servlets for debugging purposes and what not. Try outputting everything to the logs, by using

log.info("some message")

or

log.error("some error message")

1

It is in tomcat7-stdout-<date>.txt file. I am using Tomcat.

JavaTechnical
  • 8,846
  • 8
  • 61
  • 97
0

It is printed on the standard output or wherever it is redirected.

Usually logs/catalina.out (if we speak about Tomcat).

peter.petrov
  • 38,363
  • 16
  • 94
  • 159