Is there a way to get response from a jsp file as a String inside servlet. Something like
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String section1 = getResponseFromJSP();
// do something else ...
sendMailToUser(section1);
}
I’m using Servlet API 2.4 and java 1.4
A better solution might be to use another template engine like freemarker or velocity, which are independent of the servlet api and more suited for text-based emails.
However, this is possible by wrapping the
HttpServletResponseand overridinggetWritermethods. The code below works for me on glassfish.Servlet:
JSP: