- 浏览: 43408 次
- 性别:
- 来自: 长沙
文章分类
最新评论
/* * JBoss, Home of Professional Open Source * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.jboss.seam.contexts; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.jboss.seam.ScopeType; import org.jboss.seam.core.Events; import org.jboss.seam.log.LogProvider; import org.jboss.seam.log.Logging; import org.jboss.seam.servlet.ServletApplicationMap; import org.jboss.seam.servlet.ServletRequestMap; import org.jboss.seam.servlet.ServletRequestSessionMap; import org.jboss.seam.servlet.ServletSessionMap; import org.jboss.seam.web.Session; /** * Methods for setup and teardown of Seam contexts at the * beginning and end of servlet requests. * * @author Gavin King * @author <a href="mailto:theute@jboss.org">Thomas Heute</a> */ public class ServletLifecycle { private static final LogProvider log = Logging.getLogProvider(ServletLifecycle.class); private static ServletContext servletContext; public static ServletContext getServletContext() { //don't throw an exception if null, because of unit tests return servletContext; } public static void beginRequest(HttpServletRequest request) { log.debug( ">>> Begin web request" ); Contexts.eventContext.set( new EventContext( new ServletRequestMap(request) ) ); Contexts.sessionContext.set( new SessionContext( new ServletRequestSessionMap(request) ) ); Contexts.applicationContext.set(new ApplicationContext( Lifecycle.getApplication() ) ); Contexts.conversationContext.set(null); //in case endRequest() was never called } public static void endRequest(HttpServletRequest request) { log.debug("After request, destroying contexts"); try { Session session = Session.getInstance(); boolean sessionInvalid = session!=null && session.isInvalid(); Contexts.flushAndDestroyContexts(); if (sessionInvalid) { Lifecycle.clearThreadlocals(); request.getSession().invalidate(); //actual session context will be destroyed from the listener } } finally { Lifecycle.clearThreadlocals(); log.debug( "<<< End web request" ); } } public static void beginReinitialization(HttpServletRequest request) { log.debug(">>> Begin re-initialization"); Contexts.applicationContext.set( new ApplicationContext( Lifecycle.getApplication() ) ); Contexts.eventContext.set( new BasicContext(ScopeType.EVENT) ); Contexts.sessionContext.set( new SessionContext( new ServletRequestSessionMap(request) ) ); Contexts.conversationContext.set( new BasicContext(ScopeType.CONVERSATION) ); } public static void endReinitialization() { Contexts.startup(ScopeType.APPLICATION); Events.instance().raiseEvent("org.jboss.seam.postReInitialization"); // Clean up contexts used during reinitialization Contexts.destroy( Contexts.getConversationContext() ); Contexts.conversationContext.set(null); Contexts.destroy( Contexts.getEventContext() ); Contexts.eventContext.set(null); Contexts.sessionContext.set(null); Contexts.applicationContext.set(null); log.debug("<<< End re-initialization"); } public static void beginInitialization() { log.debug(">>> Begin initialization"); Contexts.applicationContext.set( new ApplicationContext( Lifecycle.getApplication() ) ); Contexts.eventContext.set( new BasicContext(ScopeType.EVENT) ); Contexts.conversationContext.set( new BasicContext(ScopeType.CONVERSATION) ); } public static void endInitialization() { Contexts.startup(ScopeType.APPLICATION); Events.instance().raiseEvent("org.jboss.seam.postInitialization"); // Clean up contexts used during initialization Contexts.destroy( Contexts.getConversationContext() ); Contexts.conversationContext.set(null); Contexts.destroy( Contexts.getEventContext() ); Contexts.eventContext.set(null); Contexts.sessionContext.set(null); Contexts.applicationContext.set(null); log.debug("<<< End initialization"); } public static void beginApplication(ServletContext context) { servletContext = context; Lifecycle.beginApplication( new ServletApplicationMap(context) ); } public static void endApplication() { Lifecycle.endApplication(); servletContext=null; } public static void beginSession(HttpSession session) { Lifecycle.beginSession( new ServletSessionMap(session) ); } public static void endSession(HttpSession session) { Lifecycle.endSession( new ServletSessionMap(session) ); } public static void resumeConversation(HttpServletRequest request) { ServerConversationContext conversationContext = new ServerConversationContext( new ServletRequestSessionMap(request) ); Contexts.conversationContext.set(conversationContext); Contexts.businessProcessContext.set( new BusinessProcessContext() ); conversationContext.unflush(); } }
node:从Servlet中我们可以获取ServletContext,HttpSession,HttpRequest,这将对Contexts非常有用,同时在ServletCycle中处理与beginSeeesin,beginRequest,init,
re-init,等与Servlet相关的处理.目的是为了设置Contexts的与ThreadLocal相关的上下文.
@see SeamListener
发表评论
-
EntityBeanSet
2009-09-23 17:08 806package org.jboss.seam.contex ... -
EntityBeanMap
2009-09-23 17:07 837package org.jboss.seam.conte ... -
EntityBeanList
2009-09-23 17:03 628package org.jboss.seam.contex ... -
AbstractEntityBeanCollection
2009-09-23 16:59 767以容器方式保存钝化是EntityBeans pack ... -
EntityBean
2009-09-23 16:38 775EntityBean 主要用来保存一个Entity的对象 ... -
PassivatedEntity
2009-09-23 16:25 790注意:PersistenceContext未确切了解,是 ... -
SeamListener -- 设置有关Contexts上下文的入口
2009-08-01 17:02 846/* * JBoss, Home of Profess ... -
上下文相关的生命周期处理 LifeCycle
2009-08-01 16:55 1805/* * JBoss, Home of Profess ... -
Seam Contexts 核心
2009-08-01 16:46 1627/* * JBoss, Home of Profess ...
相关推荐
`Servlet_LifeCycle_Demo`这个项目旨在深入理解Servlet的生命周期及其管理方法。在这个示例中,我们将探讨Servlet如何启动、初始化、处理请求、服务多个请求、以及最终销毁。 首先,Servlet的生命周期分为四个主要...
<url-pattern>/lifecycle </servlet-mapping> ``` 在这个例子中,`<load-on-startup>`元素指定了Servlet在服务器启动时自动加载的顺序。数字越小,加载越早。此外,还可以通过`<init-param>`元素为Servlet配置初始...
标题 "Tomcat 生命周期与事件管理——LifeCycle & Event" 涉及到的是Apache Tomcat服务器的核心运行机制。Tomcat是Java Servlet和JavaServer Pages(JSP)技术的开源Web应用服务器,它遵循Java EE规范,是开发和部署...
3. **生命周期注解 (Lifecycle Annotations)** Servlet 3.0允许开发者使用注解(@WebServlet, @WebFilter, @WebListener)来声明Servlet、过滤器和监听器,而不是传统的web.xml配置文件。这种方式更简洁,减少了配置...
<url-pattern>/LifeCycle </servlet-mapping> ``` 在上面的配置中,servlet 元素用于定义一个 Servlet,servlet-name 子元素用于指定 Servlet 的名称,servlet-class 子元素用于指定 Servlet 的完整包名和类名。...
Filter能够对Servlet容器的请求和响应进行检查和修改,其本身不能生成请求request和响应response,只提供过滤作用(Servlet被调用之前检查Request对象修改其相关信息,Servlet被调用后检查Response修改其相关信息),...
14.5.2 与生命周期有关的方法 118 14.6 应用程序 120 14.6.1 Bootstrap类 120 14.6.2 Stopper类 121 第15章 Digester 122 15.1 概述 122 15.2 Digester 122 15.2.1 Digester类 123 15.2.1.1 创建对象 123 15.2.1.2 ...
* 生命周期事件处理:Lifecycle 事件被用于监听和处理 Servlet 的生命周期事件,例如启动、停止和销毁。 4. 小结 本文从 Tomcat 系统架构与设计模式的角度,探讨了其工作原理的第 1 部分。在下一部分中,我们将...
- **Servlet Lifecycle**: The lifecycle of a servlet includes initialization (`init()`), service (`service()`), and destruction (`destroy()`). - **Configuration Information**: Servlets can obtain ...
Tomcat启动流程分析 组件的生命周期管理 用Lifecycle管理启动、停止、关闭 Lifecycle接口预览 ...LifecycleBase中的init与initInternal方法 ...链接器(Connector)与容器(Container) ...Servlet容器的实现。
同时,还需要对应用进行适当的设置,以启用Dynamic Faces的相关功能。 总之,Dynamic Faces通过提供对JSF的无缝集成和灵活的Ajax支持,极大地提升了Web应用的用户体验,简化了开发过程中引入Ajax的复杂性,使得...
5. **初始化和预装载servlet与JSP页面** - **分配servlet初始化参数**:使用`<init-param>`元素设置servlet的初始化参数,如`<param-name>key</param-name><param-value>value</param-value>`。 - **分配JSP初始化...
#### 一、简介与概览 Tomcat作为一款开源的Servlet容器,被广泛应用于Java Web开发之中。它不仅能够运行Java Servlet,还支持JSP技术,是学习Java Web开发的理想平台之一。本文档将对Tomcat的工作原理进行深入探讨...