aspose file tools*
The moose likes JSP and the fly likes Dynamically Creating JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Dynamically Creating JSP" Watch "Dynamically Creating JSP" New topic
Author

Dynamically Creating JSP

Brian Leblanc
Greenhorn

Joined: Jul 20, 2006
Posts: 4
Let's say you get some data from a source and you use this data and create a jsp page from it (Does not matter what data etc, you jsut use some form of data to create some jsp page). You can have this page in stream or file format.

I would be using struts.

Would it be possible to create this stream/file while in the same web container then display it?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61008
    
  65

Sure. Have a servlet that will write the text of the JSP out to a file then forward to it. The engine will detect that it hasn't yet been translated and trigger the translation. Seems like a really weird thing to do, but possible.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Brian Leblanc
Greenhorn

Joined: Jul 20, 2006
Posts: 4
Well I'm creating a preview for another page on the fly. I will have a process that converts the xml I get to a valid jsp page that will use my custom tag defeintions.

I have two routes, I can have my servelts read it as a jsp, or convert it to html manually (populate the object that my custom tags expect to generate the xml).

The problem I see with writing as a JSP is a possible threading issue.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
Another alternative would be to write the code for the dynamic page in a scripting language such as Jython or Groovy.
Your custom tags would have to be re-implemented of course.
Bill
Brian Leblanc
Greenhorn

Joined: Jul 20, 2006
Posts: 4
If I am using this creaeted file to render, then delete it on session end, would I have a problem with the class loader at all?
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by William Brogden:
Another alternative would be to write the code for the dynamic page in a scripting language such as Jython or Groovy.
Your custom tags would have to be re-implemented of course.
Bill


Just curious, why would this be a good idea in comparison to what Bear suggested? I am still trying to see the benefit of scripting languages meshed with Java.


GenRocket - Experts at Building Test Data
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
Just curious, why would this be a good idea in comparison to what Bear suggested?

What bothers me about writing a new JSP file every time a request is processed is that you end up with all these .jsp and .class files cluttering up the disk, and loaded class files cluttering up memory.
Seems to me you end up with a housekeeping problem.

I am still trying to see the benefit of scripting languages meshed with Java.

Me too so far I have not found many but so many folks are enthusiastic about scripting languages I feel I should make an effort!
Bill
Brian Leblanc
Greenhorn

Joined: Jul 20, 2006
Posts: 4
Well I was thinking of having the files naems based off the session ID for physical cleanup. The problem I run into is how to remove it from memory..

Would it be possible to use a custom ClassLoader? This is one area where I really have no expertise.

I'd like to avoid this but I don't know another way that I could render a jsp file from a String. Thats the main goal.. I get a String that is an entire jsp file (with custom tags) from an object and I need to render it.. in the same container.
 
wood burning stoves
 
subject: Dynamically Creating JSP