• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Include JSP resource from JAR file?

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?)
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic