Re: Compiling JSPs at runtime

2013-03-10 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

Gerd,

On 3/9/13 8:39 AM, Gerd Zimmer wrote:
 I'm working on a WCMS system where I want to compile some view
 components at runtime. I found the Jasper howto to compile using
 Ant, but that's not what I need.
 
 I have dynamic JSP code stored in a database.
 
 Simplified I want to do something like this:
 
 protected void doRequest(HttpServletRequest request,
 HttpServletResponse response) throws ServletException, IOException
 {
 
 int templateId = request.getParameter(templateId); String jspCode
 = db.queryString(select jspCode from templates where id = +
 templateId); Jasper jcpc = new Jasper(); Servlet jspServlet =
 jspc.compile(jspCode) forward(jspServlet);
 
 }
 
 For sure this is very simplified. I know that the Jasper JSPC will
 need much more configuration/environment set.
 
 Can someone point me to the right classes to start?

Actually, I wonder if it might make more sense to write a a DirContext
that understands your database layout and so it can ignore requests to
things that aren't your db, provide caching (if appropriate), etc.

That way, you could have Tomcat handle the URL - db-template mapping
for you. You might have to change the format of your URLs (from
/dynamic-jsp?templateId=foo to /dynamic-jsp/foo or something like
that) but it would simplify your code a lot.

I know that the whole resource-loading subsystem of Tomcat has been
recently changed drastically, so I'm not sure if there is a solution
that will work across Tomcat 6, Tomcat 7, and (eventually) Tomcat 8,
but the concept should be the same.

Invoking Jasper yourself isn't terribly easy, and once you compile,
you have to convince the JSP ClassLoader to load your new class...
that stuff isn't supposed to be controlled from the outside: it's all
supposed to be controlled by the JSP servlet. If you can make it look
like your JSP resources are on the disk (using the technique
outlined above), you can have the JSP servlet do all the dirty work
for you.

Good luck,
- -chris
-BEGIN PGP SIGNATURE-
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEAREIAAYFAlE8s5QACgkQ9CaO5/Lv0PBVUQCfXIQpltT2cpdnT99fw6t56DvJ
wjYAnRMZxa7cnLz9mrNOMTk4zvu5AlH6
=RP/Q
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



RE: Compiling JSPs at runtime

2013-03-09 Thread Martin Gainty
Zimmer http://www.jarfinder.com/index.php/jars/versionInfo/4589
Viel Gluck
Martin  
__ 
Verzicht und Vertraulichkeitanmerkung
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger 
sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung 
oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem 
Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. 
Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung 
fuer den Inhalt uebernehmen.
 

  Date: Sat, 9 Mar 2013 14:39:23 +0100
 Subject: Compiling JSPs at runtime
 From: fb666fb...@gmail.com
 To: users@tomcat.apache.org
 
 Hello!
 
 I'm working on a WCMS system where I want to compile some view components
 at runtime. I found the Jasper howto to compile using Ant, but that's not
 what I need.
 
 I have dynamic JSP code stored in a database.
 
 Simplified I want to do something like this:
 
 protected void doRequest(HttpServletRequest request, HttpServletResponse
 response) throws ServletException, IOException {
 
 int templateId = request.getParameter(templateId);
 String jspCode = db.queryString(select jspCode from templates where id =
 + templateId);
 Jasper jcpc = new Jasper();
 Servlet jspServlet = jspc.compile(jspCode)
 forward(jspServlet);
 
 }
 
 For sure this is very simplified. I know that the Jasper JSPC will need
 much more configuration/environment set.
 
 Can someone point me to the right classes to start?
 
 Thanks,
 Gerd