ServletContextListener
을 사용하여 응용 프로그램이 시작될 때 개체를로드해야합니다. 그런 다음 응용 프로그램 범위에 저장하십시오.
public class AppListener implements ServletContextListener {
public void contextInitialized(ServletContextEvent sce) {
//application is deployed
//create your object and load it
Inventory inventory = ...
//get the application context
ServletContext servletContext = sce.getServletContext();
//store the object in application scope
servletContext.setAttribute("inventory", inventory);
}
public void contextDestroyed(ServletContextEvent sce) {
//application is undeployed
}
}
그런 다음, 그에 따라 web.xml 파일에서 필터를 등록 :
<listener>
<listener-class>package.where.you.store.AppListener</listenerclass>
</listener>
응용 프로그램을 배포 한 후, 콩은 모든 사용자가 모든 페이지에서 사용 가능한 것와 표현 언어를 통해 액세스 할 수 있습니다 :
${inventory.someField}
맞아요. 문제를 자세히 설명해주십시오. –
@LuiggiMendoza이 접근법은 새로운 "inventory"객체에 대한 속성 만 설정할 수 있도록 허용하지만, 모든 JSP 페이지에서로드 및 공유하려는 디스크에 Inventory 클래스에 대한 객체를 이미 가지고 있습니다. –
그래서 애플리케이션을 시작할 때 객체를로드하고 모든 JSP 파일에서 객체를 공유하고 싶습니까? –