System.out.println is used to display text on the console and to also write events to the JVMs log.
Servlet
For example, let's say you've the following servlet. Notice the doGet method contains System.out.println("Hello World");
package com.main;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/HelloWorld")
public class HelloWorld extends HttpServlet {
private static final long serialVersionUID = 1L;
public HelloWorld() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("Hello World");
}
}
When running this servlet in Eclipse, "Hello World" is displayed on the Console tab.
Likewise, "Hello World" will be written to the JVMs log.
[1/7/19 5:46:28:501 CST] 00000253 SystemOut O Hello World
Bean/Class and JSP
In this example, MyClass contains System.out.println("Hello World");
package com.sample.main;
public class MyClass {
public myMethod(){
System.out.println("Hello World");
}
}
In the <head> of a JSP page, the People class is imported.
<%@page import="com.sample.main.People"%>
In the <body> of the JSP page, a new people object named foo is created. The text "People" must match the name of the class being imported. Using foo, get the value of the name variable. Be careful to use "out.print" and not "out.println".
<%
People foo = new People();
%>
When going to the JSP page, "Hello World" will be printed to the console.
Likewise, "Hello World" will be written to the JVMs log.
[1/7/19 5:46:28:501 CST] 00000253 SystemOut O Hello World