aspose file tools*
The moose likes Servlets and the fly likes How is the out.println() works Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How is the out.println() works" Watch "How is the out.println() works" New topic
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
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30929
    
158

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
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30929
    
158

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!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How is the out.println() works