Help coderanch get a
new server
by contributing to the fundraiser
  • 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

Save outputStream to a file

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did I ask something really stupid?
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm going to move this to the JSP forum. We may get some better input there.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Something like this?
 
J Bhatt
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi J Bhatt,

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

Thanks,
Lavjeet
 
The first person to drink cow's milk. That started off as a dare from this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic