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.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Because the
out
we're referring to isn'tSystem.out
, it's a variable in the effective method that wraps our JSP page.System.out
writes to the servlet container's console (usually a log file);out
is 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,
out
is a variable within that method, of typeJspWriter
(rather thanOutputStream
as 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.)The
out
in jsp is aJspWriter
object which is created by Jsp automatically, it is used to write something to webpage whileSystem.out.print()
is used to output/write something to the console.