1

Is there a possibility to get my displayed page's contents in "as-is" format into my request in my struts (1.2) action?

ServletInputStream is = a_request.getInputStream();;
InputStreamReader isr = new InputStreamReader ( is );
BufferedReader bufRead = new BufferedReader ( isr );
 while ((line = bufRead.readLine()) != null) {
   result += line;
}
 bufRead.close();

The value of result is "", I also tried to use

BufferedReader reader = a_request.getReader();

instead of the getInputStream, but didn't help, basically I want the JSP body into a buffer, so I can save it as HTML and convert it to PDF.

Has anyone an idea about this?

Vivek
  • 1,451
  • 8
  • 42
  • 74
  • ServletRequest.getInputStream() returns the body of the HTTP request as a binary stream. There is no HTML in there. Please explain us what you would like to do. Would you like to send the whole content of an HTML page to the server so that it's transformed into PDF? Or would you like to buffer the **response** you send to the browser in order to convert it into PDF? – JB Nizet Feb 24 '11 at 12:57
  • I would like the whole content of an HTML page to the server so I can convert it to a PDF. – Vivek Feb 24 '11 at 12:58

1 Answers1

1

You'll have to use JavaScript to get the whole HTML source code of your page (see How to get the entire document HTML as a string? and How do I get the entire page's HTML with jQuery?), and submit it (using POST) to the server.

But if the PDF converter also needs the CSS, images etc. to convert the page to PDF, it might be much harder. In this case, one solution would be to send the current page URL to the server, so that the PDF converter loads this URL and gets everything it needs to do the conversion. This means however that the page shouldn't be protected, shouldn't be generated by JavaScript, etc.

Community
  • 1
  • 1
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255