File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes can we set Servlet output stream manually? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "can we set Servlet output stream manually?" Watch "can we set Servlet output stream manually?" New topic
Author

can we set Servlet output stream manually?

indu pai
Greenhorn

Joined: Dec 29, 2004
Posts: 17
Hi,
I have a servlet which takes in the request and sends a html page with some message. for displaying this html page the following code is used.

output = response.getOutputStream();
output.print("this is file");
output.flush();

How will i know what is the Servlet output stream returned? is it a URL, on which the html file has to be displayed?Can i set it manually?

Indu
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

An output stream is for returning binary data to the client.

If you want to write text, call response.getWriter.

Example:


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
amarnath nalumachu
Greenhorn

Joined: Feb 10, 2005
Posts: 10
You can wrap to any output stream that you wish to deal with. Assume if you want your servlet to return html page then response.getWriter()/response.getOutputStream() is sufficient. But if you want your servlet to stream a zip a file, then you need to wrap the response.getOutputStream() to appropriate output stream.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61417
    
  67

"amarnath n",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
amarnath nalumachu
Greenhorn

Joined: Feb 10, 2005
Posts: 10
Hi "Bear Bibeault", My first name is "amarnath" and last name is "nalumachu". I thought it is ok to use my lastname initial "n". But anyhow, I have updated my profile.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61417
    
  67

Originally posted by amarnath nalumachu:
I thought it is ok to use my lastname initial "n".


It is not. Thank you for complying quickly with my request.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can we set Servlet output stream manually?