• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Save outputStream to a file

 
J Bhatt
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did I ask something really stupid?
 
Joe Ess
Bartender
Posts: 9320
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
J Bhatt
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9320
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm going to move this to the JSP forum. We may get some better input there.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something like this?
 
J Bhatt
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would have approached this with a servlet filter and response wrapper -- that way there's no on-page goop.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sim Kim
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi J Bhatt,

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

Thanks,
Lavjeet
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic