Isn't there any easy way in Spring 4 by which we can achieve same as following code
request.getRequestDispatcher("/WEB-INF/jsp/account_summary.jsp").include(request, response);
To get output of a JSP file as a String in our controller. Presently I am using following code for this purpose
HttpServletResponseWrapper responseWrapper = new HttpServletResponseWrapper(response) {
private final StringWriter sw = new StringWriter();
@Override
public PrintWriter getWriter() throws IOException {
return new PrintWriter(sw);
}
@Override
public String toString() {
return sw.toString();
}
};
request.getRequestDispatcher("/WEB-INF/jsp/account_summary.jsp").include(request, responseWrapper);
I need output of JSP in a String so I can build a JSON object to return back. But I am not able to find a spring only solution to achieve this.