aspose file tools*
The moose likes Servlets and the fly likes Get the rendered JSP HTML content at server side Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Get the rendered JSP HTML content at server side" Watch "Get the rendered JSP HTML content at server side" New topic
Author

Get the rendered JSP HTML content at server side

Mandy Ram
Greenhorn

Joined: May 09, 2012
Posts: 16
I want to convert a JSP page to a PDF. For this I am using a third party library which accepts HTML as input.
So, on the server side, I have to get the complete HTML which is the result after the JSP is rendered and then pass the same HTML to my third party library.
I am able to accomplish this by writing a filter, which wraps the response in to byte array output stream. I am able to get the complete HTML of the rendered JSP including the rendering of Tiles. This thing cannot be achieved in a controller or servlet as I need to final HTML output(including tiles, any JSP tags present in the JSP and others)
But, as per the requirement, I need to get some information from the DB and so I thought interacting with DB from a filter is not a good idea. Can anyone suggest a good place where I can do this instead of a filter?

I tried accessing the BO or DAO object from the Filter, but as my application using spring dependency injection, I have to invoke the filter also using spring which is not possible and so the BO and DAO and jpaDataAccess object in the DAO can’t be auto wired.
So, instead of getting the complete HTML in filter, Please suggest a good place where and how I can accomplish the same.

Mandy Ram
Greenhorn

Joined: May 09, 2012
Posts: 16
Figured it out!!

We can do a request dispatcher in the normal Spring controller passing a wrapped response.

We can get the complete HTML from that response object.

Thanks!
Akhil Khandelwal
Greenhorn

Joined: Jul 08, 2013
Posts: 1
Will you please explain How to pass a wrapped response in a Spring controller??
Mandy Ram wrote:Figured it out!!

We can do a request dispatcher in the normal Spring controller passing a wrapped response.

We can get the complete HTML from that response object.

Thanks!
Mandy Ram
Greenhorn

Joined: May 09, 2012
Posts: 16
Akhil Khandelwal wrote:Will you please explain How to pass a wrapped response in a Spring controller??


For getting the HTML content in the server side, no need to wrap the request.You can just wrap the response and pass it in the request dispatcher and then, get the content from wrapped response's toByteArray method.
You can follow this link to see how to wrap the response before passing to request dispatcher-> http://angelborroy.wordpress.com/2009/03/04/dump-request-and-response-using-javaxservletfilter/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Get the rendered JSP HTML content at server side
 
Similar Threads
Which technology is best to study in parallel
Best 3D option in an applet?
JAX-WS Service using IBM WAS and Spring Injection mechanism
How are tiles different than include?
securing the data tempering by intercepting the http request