This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
I have a JSP fragment located within a JAR file loaded into the classpath via the web app's WEB-INF/lib folder. I'd like to include the processed results of the JSP as part of a servlet's response output. Is this possible?
I've tried a number of URL formats to RequestDispatcher.include() to no avail.
I have been able to access the fragment via JarURLConnection, but that simply returns the unprocessed source of the JSP.
I do something like this ... After reading the jsp snippet from a stream, in your case from the jar file, I HTTP POST the jsp snippet to a servlet. it is passed as a request parameter called "jsp". The code of the interpreter servlet is reproduced below....Works for me.
[ November 03, 2004: Message edited by: Ajith Anand ] [ November 03, 2004: Message edited by: Ajith Anand ]
Ajith, thanks for posting that. I had thought of that approach, but I'd really rather not have to write the fragment out to the file system. Btw, you could simplify your code by using the RequestDispatcher include mechanism to snarf in the file once you've written it out to the file system (where it now acts just like any other JSP fragment). I'd also put in logic to only have to write the file out once rather than each time is is referenced.
I may have to resort to writing temp files, but I'm still investigating cleaner possibilities...
Joined: Aug 30, 2004
Update me also if you have any cleaner possibilities...I could not use RequestDispatcher include mechanism because it does the inclusion runtime.There is no way I could snoop for the JSP; compiled and executed output.
We had a requirement where we were doing a passive jsp compilation, and execution of the compiled class and collection of the output in a buffer. A proprietary templating mechanism would then use this buffer along with other content-types from a database, dynamically and publish....goes without saying that the publishing server isnt J2EE ...
If I were going to go that route, I'd abstract the whole mechanism so that the parts weren't even aware that anything was being extracted from the jar. I'd map a URL to a 'resource' servlet that would check to see if the resource had already been extracted, and if not, extract it. Then, it would use the include mechanism to suck the file in.