What's the easiest way to make a JSP page render, then get the rendered html content as a string?
There is this tutorial, which explains every step with code:
http://valotas.com/get-output-of-jsp-or-servlet-response/
Doing it this way has advantages when the JSP is not accessible by URL directly.
You should provide your own wrapper for the Writer
of HttpServletResponse
(via HttpServletResponseWrapper
in a Filter
), and each time you write to that writer, also store in a StringBuilder
.
That's just a sketch of the code, there is a sufficient number of examples, but the main steps are:
PrintWriter
to make it store each write in a builderHttpServletResponseWrapper
and make it return the writer wrapperchain.doFilter(request, new HttpServletResponseWrapper(response))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With