Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

difference between out.println() and System.out.println() in JSP?  RSS feed

 
yamini nadella
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(1)
<HTML><BODY>
Hello user! You are using a computer <B><%int i=10;System.out.println("first line "+i);%> </B>
Hello user2! You are using a computer <B><% System.out.println(" this is \n new line "+i);%> </B>
</BODY></HTML>

This JSP program gave output as

Hello user! You are using a computer Hello user2! You are using a computer

Why it did not print "first line 10"...etc. why it did not executed System.out.println("")?

(2)
<HTML><BODY>
Hello 1 <B><%int i=10;out.println("first line "+i+6);%> </B>
Hello 2 <B><% out.println(" this is \n new line "+i+6);%> </B>
</BODY></HTML>

output of this jsp is like below.

Hello 1 first line 106 Hello 2 this is new line 106

Here even I kept \n between "this is" and "new line" why it printed everything in one line?.

How to print Hello1 and Hello2 statements in two seperate lines?

(3)what is the difference between out.println and System.out.println?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65825
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) System.out is a stream to the console, not the response. This output will appear in the console window or log file (wherever your container sends it).

2) The newline character (\n) in an invisible separator in HTML. The browser (in general) just ignores it.

3) See 1 and 2.

Now for the big question: why are you bothering with out? Just use template text for your output.
 
Srinivas Gogineni
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
In Jsp i f we want to write some thing to response object we need to use out.println("some value");

in java if you want to write some thing to the console then we will write in System.out.println("Some thing"+strSomeval)

you can check in your web container log for you System.out.println(" ");

In the jsp/Browser can understand what we have written in response object.
Thx and regards
-Srini
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65825
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
n Jsp i f we want to write some thing to response object we need to use out.println("some value");


That is incorrect. While 'out' will stream to the response, it is not needed. This is the purpose of template text.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!