aspose file tools*
The moose likes JSP and the fly likes Save outputStream  to a file 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 » JSP
Bookmark "Save outputStream  to a file" Watch "Save outputStream  to a file" New topic
Author

Save outputStream to a file

J Bhatt
Greenhorn

Joined: Jun 15, 2005
Posts: 20
I need to save the generated html page (on the server) as a html or pdf file.I was thinking of writing a filter/servlet which does this before the page is displayed .
Is this something which can be achieved ?
Can the OutputStream that is deliverd to the webpage be converted to something.html before it is rendered ?
Please advise.
Thank you .
J Bhatt
Greenhorn

Joined: Jun 15, 2005
Posts: 20
Did I ask something really stupid?
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8927
    
    9

Maybe, maybe not. As our FAQ entry, Patience Is A Virtue states:

. . . if you finally decide to bump the post, please try to do so by posting more information! After all, if nobody answered, that's probably because nobody did know an answer.

Your question is quite vague. Are you generating the HTML in a servlet and writing it to the OutputStream? That can be solved with something like the Unix tee command. Create a custom OutputStream that writes one value to two outputs. If you are using JSP's, I don't know if what you want to do is possible, so give us some more details and we may give you more options.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
J Bhatt
Greenhorn

Joined: Jun 15, 2005
Posts: 20
Sorry for not being very specific. I am using the struts framework and jsp pages are generated using the framework .I need a image or a static html version of the jsp page that was filled out by the user , I was able to create a filter and also wrote wrappers around HttpServletResponseWrapper and ServletOutputStream and save the stream to a file as html file. But I have to read back the saved file and display it to the user.

Here is the code snippet


Now that I got that working , this page may or maynot be accessed by the user, I wanted to know If I could call a jsp file and provide the sessionId or something so that I can save the review page behind the scenes.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8927
    
    9

I'm going to move this to the JSP forum. We may get some better input there.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Something like this?


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
J Bhatt
Greenhorn

Joined: Jun 15, 2005
Posts: 20
yeah something similar to that.
I am trying to get this piece of code working now.



Where FileResponseStream and FileResponseWrapper are wrappers around the HttpServletResponseStream and HttpServletResponse.
I do not get anything back , my byte[] is 0 .
J Bhatt
Greenhorn

Joined: Jun 15, 2005
Posts: 20
Just In case anybody was intersted, I got around this problwm by using a custom JSP tag that takes the bodycontent and writes to a file.
So I just did this in the jsp , so the content of this page is written out to a file.
<capture:bodyGrab><jsp:include page="/myPage.jsp" flush="true" /></capture:bodyGrab>
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

I would have approached this with a servlet filter and response wrapper -- that way there's no on-page goop.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Bear Bibeault:
I would have approached this with a servlet filter and response wrapper -- that way there's no on-page goop.



I have a small test project that uses a filter and wrapper to do dump the contents of the page to stdout on my site. It should make for a good starting point.
http://simple.souther.us/capture.war


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Sim Kim
Ranch Hand

Joined: Aug 06, 2004
Posts: 268
Hi J Bhatt,

Can I get the source files for the tag you have made .

Thanks,
Lavjeet
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Save outputStream to a file