• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to save the servlet response to a file !

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Tanu M
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic