This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamically Creating JSP

 
Brian Leblanc
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64851
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Brian Leblanc
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13062
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13062
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic