wood burning stoves 2.0*
The moose likes Servlets and the fly likes How to save the servlet response to a file ! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to save the servlet response to a file !" Watch "How to save the servlet response to a file !" New topic
Author

How to save the servlet response to a file !

Tanu M
Greenhorn

Joined: Jul 12, 2001
Posts: 3
Hi,
I'm forwarding the HttpServletRequest object from one servlet to another and I want to save the response(that the second servlet sends) to an html file in some other directory of the web server.
Is this possible and how ?
Thanks,
Tanu.
Rehan Malik
Ranch Hand

Joined: Jul 09, 2001
Posts: 76
Originally posted by Tanu M:
Hi,
I'm forwarding the HttpServletRequest object from one servlet to another and I want to save the response(that the second servlet sends) to an html file in some other directory of the web server.
Is this possible and how ?
Thanks,
Tanu.


One way to do this would be to first see if you have permissions to write to the directory on the web server. If you do have the permissions, then simply just open an outputstream to the file and specify the file destination when you declare the "File" class.
Let me know if you want some code.
I'm too lazy to write it right this second unless specifically asked =P


Rehan Malik
Tanu M
Greenhorn

Joined: Jul 12, 2001
Posts: 3
Thanks for the response, But it's not solving my problem. Actually I want second servlet to send the response to the first one and then First servlet should save the response to an (HTML)file.
I tried using ServletOutputStream but could not proceed with that.
It would be great if you could send the code too.

Rehan Malik
Ranch Hand

Joined: Jul 09, 2001
Posts: 76
Okay sure, the code isn't a problem but I just want to make sure the specifications are correct.
What is known?
Servlet A and Servlet B exist
Servlet A receives input from user.
Servlet A sends information to Servlet B.
(This is where I need clarification)
Servlet A stores the response to a file? (Or is it Servlet B)
Also, what information should be saved to the file? Just the request parameters?
If you could reply to those questions, I'll probably have the code within a day (mainly because I'm going home in a few minutes and I probably won't get a chance to write the code after I leave until tomorrow morning).

Originally posted by Tanu M:
Thanks for the response, But it's not solving my problem. Actually I want second servlet to send the response to the first one and then First servlet should save the response to an (HTML)file.
I tried using ServletOutputStream but could not proceed with that.
It would be great if you could send the code too.

Tanu M
Greenhorn

Joined: Jul 12, 2001
Posts: 3
Thanks once again ! I'm mentioning the specifications here:
1. It's known that servlet A and Sevlet B both exist.
2. It's right that:
"Servlet A receives input from user.
Servlet A sends information to Servlet B."
i.e. A is receiving the HttpServletRequest and sending that to servlet B using "include()" of "RequestDispatcher".
now the ServletA has to save the response that servlet B is sending to it. By default this response is sent to the client(Browser) but I need to save this though it may or may not be sent to the browser. Saving the response(HTML page) of ServletB, is what I need.
Please do let me know if I need to be more specific.
Thanks & Regards,
Tanu.
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
"Tanu M",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in with a new name which meets the requirements.
Thanks.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

I believe this is possible using WebLogic but I'm not sure about the others. THi is something I wanted to mess around with a while back but never got the time...
(this is the short desc cos I don't have the time at the moment)
It may be that the class that manages loading and executing a Servlet is configuarble via properties. If this is the case it may be possible to extend its functionality and insert your own class. The purpose of this would be to either force it to use your implmentation of ServletStream (so that it creates two versions invisibly to the user) or some other mechanism to fork the data.
Haope this is a step forward,
dave
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to save the servlet response to a file !