aspose file tools*
The moose likes JSP and the fly likes How to manually invoke jsp servlet? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How to manually invoke jsp servlet?" Watch "How to manually invoke jsp servlet?" New topic
Author

How to manually invoke jsp servlet?

Dudley Dawson
Ranch Hand

Joined: Dec 14, 2004
Posts: 57
Hi-
I would like to generate JSP source code on-the-fly. Is there any way I can pass this source dynamically to the jsp servlet using the spec? Rather than forwarding/including a request through requestdispatcher that loads the jsp source from the filesystem.

Is there any way to do this?

thanks.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Yuck, why?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61426
    
  67

Makes me shiver just to think about it. What are you really trying to accomplish? Perhaps there's a cleanly supported way of doing it.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Dudley Dawson
Ranch Hand

Joined: Dec 14, 2004
Posts: 57
Yeah. I know. Sounds messy.

It's hard to explain. Basically, I'll be piecing together bits of content and model data from various sources in a servlet (most likely a Spring controller, if that makes any difference) into an xhtml document. That resulting document may contain JSP code that needs to be executed after it's cobbled together.
I checked out the implementation of apache's jasper servlet (org.apache.jasper.servlet.JspServlet). Looks like the streaming, compilation, and processing of the jsp page is left up to each vendor, done in the service() method. So - there's doesn't seem way to uniformly pipe in jsp code and have it compile & execute.

I *may* be able to whittle the requirement down to not support scriptlets, and only process XML jsp tags and other JSTL tags. Is there a way i could parse the document, and kick off each tag as i bit it? But i guess there would be all kind of contexts that I would not have available.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I still don't understand the part of the requirement that requires you to dynamically generate and evaluate JSP.

Not that this is completely relevant, but in 10 years of writing Java-based web applications, including ones with *very* demanding client-side requirements, I've *never*, ever had to do this--it strikes me as very unlikely (but possible, I suppose) that what you're proposing is necessary (and it's *certainly* not good).

Without a simple use-case, however, it's impossible to know what to suggest as an alternative. But I just don't see it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to manually invoke jsp servlet?