Portal開源實現-Liferay的Portlet Session處理(1)

來源:互聯網
上載者:User

一、規範中的SESSION描述

(PortletSession objects must be scoped at the portlet application context level. Each portlet application has its own distinct PortletSession object per user session. The portlet container must not share the PortletSession object or the attributes stored in it among different portlet applications or among different user sessions.)
上面這段話是portlet規範裡的一段。很明白的可以看出,每個Portlet Application應該在Process Action和Render的時候應該擁有自己私人的Session對象,來為目前使用者服務。也就是說,如果某一個使用者在一個PORTAL系統中操作不同的PORTLET,而且這些PORTLET屬於不同的PORTLET APPLICATION,則,這個使用者將操作多個SESSION對象,使用者在每個PORTLET中操作SESSION時,這個SESSION都將是屬於該PORTLET所在的內容相關的私人SESSION 對象。比如,使用者當前頁面有三個PORTLET,每個PORTLET都屬於不同的PORTLET APPLICATION。則當該使用者在第一個PORTLET裡面有對SESSION的操作後,該PORTLET所屬的APPLICATION將為這個使用者產生一個SESSION;當該使用者又操作第二個PORTLET中的SESSION時,該上下文有會對此使用者產生一個新的SESSION對象;第三個依然如此。加上PORTAL系統的SESSION,也就是該使用者實際和四個SESSION在大交道。

另外要說明一點的是,PORTLET APPLICATION和WEB APPLICATION的關係。規範中有如下的定義:
(Portlets, servlets and JSPs are bundled in an extended web application called portlet application. Portlets, servlets and JSPs within the same portlet application share class loader, application context and session. )
這說明PORTLET APPLICATION其實就是一個WEB APPLICATION。規範中還有一段話更是說明了這個問題,同時也強調了PORTLET SESSION 和普通的該APPLICATION的SESSION的關係:
(A Portlet Application is also a Web Application. The Portlet Application may contain servlets and JSPs in addition to portlets. Portlets, servlets and JSPs may share information through their session. The PortletSession must store all attributes in the HttpSession of the portlet application. A direct consequence of this is that data stored in the HttpSession by servlets or JSPs is accessible to portlets through the PortletSession in the portlet application scope. Conversely, data stored by portlets in the PortletSession in the portlet application scope is accessible to servlets and JSPs through the HttpSession. If the HttpSession object is invalidated, the PortletSession object must also be invalidated by the portlet container. If the PortletSession object is invalidated by a portlet, the portlet container must invalidate the associated HttpSession object.)

最後一點要說明的是怎樣得到PORTLET SESSION對象。規範中有這樣一個例子:
PortletSession session = request.getSession(true);
URL url = new URL(“http://www.foo.com“);
session.setAttribute(“home.url”,url,PortletSession.APPLICATION_SCOPE);
session.setAttribute(“bkg.color”,”RED”,PortletSession.PORTLET_SCOPE);

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.