I started learning jsp and I am seeing that, if we want to print something in jsp,we have to write out.println() instead of System.out.println(), but if we write System.out.println() it does not show any error but does not o/p to the browser also. I want to know why it happens? As all we know that System is a predefined class and out is the output stream connected to the console. So why we do not require to write System in jsp?
Thanks.
I started learning jsp and I am seeing that, if we want to print
Share
Because the
outwe’re referring to isn’tSystem.out, it’s a variable in the effective method that wraps our JSP page.System.outwrites to the servlet container’s console (usually a log file);outis a different class entirely which writes to the output stream for the generated response.When a JSP is turned into code, it (in theory, and with Tomcat, in fact) goes through two steps: JSP -> servlet source code, then servlet source code -> class. The entire page is put inside a method, which with Tomcat looks something like this:
As you can see,
outis a variable within that method, of typeJspWriter(rather thanOutputStreamas withSystem.out).(Side note: Code you include in
<%! ... %>tags rather than the normal<% ... %>tags isn’t put in the method; it’s put elsewhere in the generated servlet class.)