| Author |
How is the out.println() works
|
Arun Giridharan
Ranch Hand
Joined: Sep 30, 2010
Posts: 290
|
|
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
internet detective
Marshal
Joined: May 26, 2003
Posts: 26192
|
|
|
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.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26192
|
|
|
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
Joined: Sep 30, 2010
Posts: 290
|
|
|
Got it!!
|
 |
 |
|
|
subject: How is the out.println() works
|
|
|