论坛首页 入门讨论版 Spring

Put objects into servlet context(applicationLevel)

浏览 138 次
该帖已经被评为新手帖
作者 正文
时间:2008-05-03 关键字: spring
1. create a bean to implements the ServletContextAware, and spring will automatically set the servletContext:

public class ApplicationScopeObjectSettings implements ServletContextAware {
ServletContext servletContext;

public void setServletContext(ServletContext servletContext) {
this.servletContext = servletContext;
servletContext.setAttribute("appScope", "appScope" + (new java.util.Date()));

}
}


2. in xml file:
<bean id="ApplicationScopeObjectSettings" class="ApplicationScopeObjectSettings"/>

3. Then you can access the appScope in application scope in your jsp
page.
   
论坛首页 入门讨论版 Spring

跳转论坛:
JavaEye推荐