首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> Java 程式設計 >> Java 相關知識

Portlet 規範中的 Session 語義與 Liferay 實現差距 (一)

     編輯:Java 相關知識

規範定義:Portlet Session 作用域 = Portlet Application Context

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 App 的 Portlet,將產生三個獨立的 Portlet Session (加上 Portal 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 Session 必須將屬性儲存在該 Portlet App 的 HttpSession 中。Portlet、Servlet、JSP 可透過各自 Session 介面互通數據。任一 Session 失效,另一個必須同步失效。

取得 Portlet Session 標準範例

PortletSession session = request.getSession(true);
URL url = new URL("https://www.foo.com");
session.setAttribute("home.url", url, PortletSession.APPLICATION_SCOPE); // 跨 Portlet 共享
session.setAttribute("bkg.color", "RED", PortletSession.PORTLET_SCOPE);   // 單 Portlet 私有

兩大作用域:APPLICATION_SCOPE (同 Web App 內可見) / PORTLET_SCOPE (僅當前 Portlet 可見)。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved