JSP application scope objects in Java library
I am working on a preexisting web application built with JSP, which uses an ext开发者_运维技巧ernal Java library. I want to make some JavaBeans that were instantiated with jsp:useBean tags available to the Java code.
What would be a good practice to do that? I suppose I can pass the objects in question to every function call that requires them, but I'd like to avoid that.
Application scoped objects are stored as attributes of the ServletContext
. If the "function call" has access to the ServletContext
, then it can just grab them as follows:
Bean bean = (Bean) servletContext.getAttribute("beanname");
I of course expect that the "function" is running in the servlet context. I.e. it is (in)directly executed by a servlet the usual way.
精彩评论