Hi there,
I have a JSP in a string variable in a servlet and I would like to compile it as a JSP myself (on the fly, programatically). Right now what I am doing is saving the string to a file and accessing that file (which generates the resulting servlet) - something like:
// and He created JSP from mere html code
final String jsp = convertToJSP(someHTML);
// create a jsp file with the above
final File jspFile = new File(getServletContext().getRealPath("/"), jspFilename);
// write it to a file FIXME: This must be expensive, the user is waiting
// I DONT WANT TO WRITE THIS TO FILE: GENERATE SERVLET IMMEDIATELY FROM CODE
FileUtils.writeStringToFile(jspFile, jsp, "UTF-8");
// access that jsp
resp.sendRedirect(jspFilename);
This is obviously expensive and requires an IO operation. Any ideas/suggestions on how to do this ?
I understand that I'll have to use/tie down to tomcat jasper (jspc) at some point and I am fine with that (Tomcat is my servlet container).
Many Thanks, JP