Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How is the out.println() works

 
Arun Giridharan
Ranch Hand
Posts: 290
Debian Fedora Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not getting ,how this out.println() works ,can someone explain ,just eager to know ,how it get's handled .

In my scenario i send data to servlet through request object , in servlet
|
| below (and i'm using out.println() to send the data) , i don't see the display of the data (the thing i have given in servlet) and it's moved to "result.jsp" without giving display to the servlet. !!



My question is

1) Is the response is sent when i use out.println() in the servlet , (if it was sent both request and response might have got de-referenced but i get "result.jsp" , i guess i don't know what's happening). Is "out.println() statement is working or not"
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34422
347
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PrintWriter is a stream. Your calls to println() put messages on the stream to be output "later." They don't get sent to the browser right away. They get sent when you call flush() or close(). See this example. You use flush() when you want to write more in the same servlet (like in a download - you want to start downloading something while you get the rest of the data.) You use close() at the end.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34422
347
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, you can't use out.println and forward to a JSP in the same example. It's one or the other as the JSP expects to start with a clean slate.
 
Arun Giridharan
Ranch Hand
Posts: 290
Debian Fedora Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic