1

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.

Paul
  • 4,812
  • 3
  • 27
  • 38
  • just to add... I would like to add "features" for example, calling a page with parameters "abc.txt?name=John". So basically jsp would be perfect. Its just that i cant get it to run standalone. I even have the option to run in a web container but i am not sure that helps. – Paul Jun 24 '10 at 22:12

4 Answers4

2

To answer my own question :)

I created classes that implement tomcat's Connector interface, which allowed me to use everything that Tomcat offers but with my own entry point.

Paul
  • 4,812
  • 3
  • 27
  • 38
0

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
  • 3,634
  • 1
  • 25
  • 36
  • 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 Jun 24 '10 at 22:01
  • http://velocity.apache.org/tools/releases/2.0/ You can do that as well. – Jim Barrows Jun 24 '10 at 23:51
0

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
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • 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 Jun 25 '10 at 05:45
  • 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 Jun 25 '10 at 11:03
0

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
  • 5,793
  • 14
  • 53
  • 88