| Author |
Include JSP resource from JAR file?
|
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56224
|
|
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. Anyone ever try this before? (and succeed?)
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Ajith Anand
Ranch Hand
Joined: Aug 30, 2004
Posts: 40
|
|
Hi Bear, 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. Interpreter.jsp [ November 03, 2004: Message edited by: Ajith Anand ] [ November 03, 2004: Message edited by: Ajith Anand ]
|
LXI Technologies P Ltd
[url]www.lxisoft.com[/url]
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56224
|
|
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...
|
 |
Ajith Anand
Ranch Hand
Joined: Aug 30, 2004
Posts: 40
|
|
Hi Bear, 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 ... it might be helpful to me also..
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56224
|
|
|
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.
|
 |
 |
|
|
subject: Include JSP resource from JAR file?
|
|
|