Nov 30th, 2009, 01:38 PM
Rendet JSP output as PDF (or make an internal request)
I have a Spring 2.5 WebMVC application with enabled Spring Security for all URLs. Now I need to transform an existing Tiles/JSP page into a pdf. From the HTML / CSS side it's no problem, but my issue is that I didn't find a way to pass the output to my PDF library (iText / Flying Saucer).
- I don't want to create a PDF Object and create the page with addParagraph() and so on, because it's already there in HTML and the conversion should be fine.
- I don't want to make a "real" http request to another controller since I would have to bypass all the security settings somehow.
A perfect solution for me would be something like an "internal request", so I tell Spring the URL as well as the request parameters and I get the executed response (from Tiles/JSP) back. This I could give to itext and everything should be fine :-)
String html = magicClass.renderView(myJspUrl,myRequestParameters );
Is there any way to do this?
Nov 30th, 2009, 02:16 PM
The key problem in this case is that you have to pass HttpServletResponse object to JSP rendering engine anyways.
Probably you can use MockHttpServletResponse from Spring Testing framework, hovewer, it is not an elegant solution because it's definitely misuse of that class.
Also you can use HttpServletResponseWrapper to create a wrapper around the actual HttpServletResponse and redirect JSP output to the in-memory buffer, but it requires a lot of code.
Tags for this Thread