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

printwriter vs system.out.println  RSS feed

 
tushar panda
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


in the program above why printwriter is used & why system.out.println is not used .

moreever is system.out.println & out.println mean the same thing .
 
Vinod K Singh
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anything printed with PrintWriter will be visible on the browser while System.out.println's output will be visible on server console.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the button on your post.

 
tushar panda
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vinod K Singh wrote:System.out.println's output will be visible on server console.


thanks but what server console . does it mean anything displayed on browser or server part uses printwriter & everything realated to destop or instant display uses System.out.println .
 
Vinod K Singh
Ranch Hand
Posts: 198
 
kiran mathew
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the code sample you have given,

The PrintWriter object is that obtained from the response. The intention of the code is to write the contents to the response and that response will be rendered by the browser.

System.out is used to print data to the console.

You can find the difference by replacing the code with
PrintWriter printWriter = new PrintWriter(System.out);
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is in fact bad practice. Presentation logic belongs in JSP, not in Servlet.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!