开发者

JSP application scope objects in Java library

开发者 https://www.devze.com 2023-01-01 18:01 出处:网络
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 t

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消