If presentation templates should be dynamically retrieved from the database, you should not think about JSPs. JSPs are compiled into servlet classes and there is little support for this other than the standard one (static files somewhere under your webapp root).
Therefore, just consider switching the viewing technology (at least for the dynamic part) to some general-purpose template library, such as Velocity or Freemarker . This is due to the security bonus, as there may be less in this template than from the JSP code.
You can even support multiple viewing technologies (perhaps something that Spring MVC supports off-the-shelf, with the exception of JSP) and allows your users to choose the type of template at boot time.
Then you can write your own custom view, which will be delegated to the corresponding standard recognizers (Velocity, Freemarker, XSLT, independently ...) with the template selected by the user.
However, if JSP is a tough requirement, I think that one ugly workaround for JSP (which should work in any servlet container) could be to extract the contents from the database and create the actual file (e.g. WEB-INF/templates/${primarky-key}.jsp ) under your exploded root webapp, then RequestDispatcher.forward() to it.
source share