Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serve JSP stored in DB

I want to server a JSP page that is stored in a database as a blob. So if a request comes in at the url http://mydomain.com/app/list.jsp I know to go to the DB to retrieve the resource list.jsp.

I am using spring and tiles, so have adispatcher servlet and controllers set up and working in traditional sense. Would this be similar in principle to the resource servlet that spring web has to serve javascript files and messages from within jar?

Note that the JSPs would not just be static HTML, I will have beans (model attributes) associated with the page, so will still want to use EL to query the bean.

Cheers

like image 900
user223695 Avatar asked Dec 03 '09 13:12

user223695


People also ask

Can JSP deployed in Web server?

Because JSPs are part of the J2EE standard, you can deploy JSPs on a variety of platforms, including WebLogic Server.

How Java is embedded in JSP?

The Java statements are placed inside the _jspService() method of the translated servlet as "it is". Scriptlets form the program logic. JSP Expression <%= .... > : used to evaluate a single Java expression to obtain a value. The Java expression is placed inside a out.

Is JSP deprecated?

"JSP technology is considered to be a deprecated presentation technology for JavaServer Faces."


2 Answers

JSP loading and compiling is implemented in the servlet container. There are two approaches I can think of using for making this feature possible:

  1. Modify the servlet container's JSP servlet. If you are using, say, Jetty or Tomcat which are open-source, you can easily look at their JSP servlet and change it so that it reads the JSPs from the DB. You may be able to adapt one of these for use in a proprietary container. This is the most direct way of solving the problem but you are stepping into a minefield of potential bugs.
  2. Build the CMS in the database as planned, but copy the JSPs to the running application's filesystem while the application is running. Let the application server's normal JSP change detection notice that the changes are occurring. You could wrap all requests with a Filter which checks the DB for updated JSPs, copy the JSPs at modification time, or use a scheduled job to copy them at certain intervals.

In both scenarios you have to worry about memory leaks for unloaded classes, especially if any of your code uses ThreadLocals or other static variables. The normal JSP loaders already suffer from problems if you unload WARs or recompile JSPs at runtime. This is due to limitations in Java and is not easily solved (depending on which JDK is used). I would recommend never, or very rarely, changing JSPs without restarting the server unless you can't avoid it.

like image 181
Mr. Shiny and New 安宇 Avatar answered Nov 15 '22 11:11

Mr. Shiny and New 安宇


See for example Eval taglib from Coldtags suite: http://www.servletsuite.com/servlets/evaltag.htm

like image 21
Den Avatar answered Nov 15 '22 10:11

Den