views:

50

answers:

3

Hello,

I am starting a project that will have many "files" (like a web servers .html or jsp files). Each of these files will have "JSP" embedded in the files, for example;

Hello <%="John Doe" %>

I would then like to programatically send this file through a "JSP Compiler" and then get the output file.

I have looked at the Tomcats JSPServlet and came to a dead end as it does not seem possible to get to the Servlet object from code. I have also downloaded the Apache Jasper code which is in Tomcat to figure out what JSPServlet is doing but this seems like the long route.

Does anyone have any suggestions or ideas?

I know JSP is web orientated but that will work for me.

A: 

That is the long route. Are you looking for a way to generate files using a template? Velocity or Freemarker might be a better route in this case. especially if you don't want html generated.

Jim Barrows
I looked at those. I do need a template but at the same time i need to embed actual java code to be executed... just like JSP scriptlets.
Paul
http://velocity.apache.org/tools/releases/2.0/You can do that as well.
Jim Barrows
A: 

You just want to get its output? Easiest way is to just install a servletcontainer, deploy the webapp and use URL#openStream() to get an InputStream of it.

InputStream response = new URL("http://localhost/context/page.jsp").openStream();
BalusC
I have thought about that. To be honest i dont like that method because i think there might be a performance knock. I also cant see why i cant "bypass" network/loopback and tcp stack etc.
Paul
This isn't a performance knock if the webserver is installed at the same machine. Bypass isn't possible since the server listens on a TCP/IP socket only.
BalusC
A: 

Tomcat will compile the JSP files for a web-app and place it in a special folder for each web-app.

What you can do is write a script to periodically dump jsp files sent by users inside a Whatever.war directory inside your Tomcat webapps directory.

That way Tomcat will automatically compile the JSP's and give you the output HttpServlet code,

You can then check the Tomcat logs for any compile exceptions for each of those JSP files.

Check out this article about doing it from Ant using the Jasper compiler and from Apache Web Site.

Koekiebox