作爲liferay/portal/portlet開發的新手段,您每天都會遇到問題。現在我試圖從一個portlet註銷,但還沒有找到一種方法來實現它。你應該怎麼做?我應該嘗試發送某種註銷事件還是什麼?在Liferay資源中徘徊我發現了一個LogoutAction.java,看起來很有前途,但是如何觸發它呢?從liferay portlet觸發註銷
最好問候安德斯奧姆
作爲liferay/portal/portlet開發的新手段,您每天都會遇到問題。現在我試圖從一個portlet註銷,但還沒有找到一種方法來實現它。你應該怎麼做?我應該嘗試發送某種註銷事件還是什麼?在Liferay資源中徘徊我發現了一個LogoutAction.java,看起來很有前途,但是如何觸發它呢?從liferay portlet觸發註銷
最好問候安德斯奧姆
嘗試actionResponse.sendRedirect( 「/ C /門/註銷」)
sendRedirect僅在ActionResponse上,而不在RenderResponse或ResourceResponse上。 – 2012-05-04 16:56:10
您可以創建一個註銷鏈接到Liferay的內部註銷功能像這樣在你的JSP:
<%@page import="com.liferay.portal.util.PortalUtil"%>
.
.
<a href="<%= PortalUtil.getPortalURL(request) %>/c/portal/logout">Log Out</a>
2之後-3天的調查,我實現了與Ajax調用登錄和註銷。註銷它並不像調用session.invalidate()那麼簡單,但只需要配置一點點。我會寫我如何實現這一點:
首先編寫portal-ext.properties並添加此行: session.enable.phishing.protection =假
然後在所有你的Portlet您必須設置private-session-attributes爲false。訂購是重要的,所以我會告訴你的地雷:
<portlet>
<portlet-name>home</portlet-name>
<icon>/icon.png</icon>
<instanceable>false</instanceable>
<private-session-attributes>false</private-session-attributes>
<header-portlet-css>/css/main.css</header-portlet-css>
<footer-portlet-javascript>/js/home.js</footer-portlet-javascript>
<css-class-wrapper>home-portlet</css-class-wrapper>
</portlet>
一旦這樣做了,其餘的很簡單。對於日誌中:
public static void login(ResourceRequest request,ResourceResponse response, String liferayUser, String liferayPassword) throws Exception{
MethodKey key = new MethodKey("com.liferay.portlet.login.util.LoginUtil", "login", HttpServletRequest.class, HttpServletResponse.class, String.class, String.class, boolean.class, String.class);
PortalClassInvoker.invoke(false, key, new Object[] { PortalUtil.getHttpServletRequest(request), PortalUtil.getHttpServletResponse(response), liferayUser, liferayPassword, false, null});
}
而對於註銷:
public static void logout(ResourceRequest resourceRequest) throws Exception{
HttpServletRequest request = PortalUtil.getHttpServletRequest(resourceRequest);
request.getSession().invalidate();
}
我用ResourceRequest因爲我是做Ajax調用。唯一的「問題」是,如果您登錄並且想要註銷&登錄其他用戶,您必須執行2次ajax調用(第二次從第一次調用返回)。
你爲什麼不呈現常規的註銷鏈接? – ewernli 2010-06-18 12:52:26
我必須從我的一個bean中觸發註銷。 – Buzzzz 2010-06-18 14:35:46
但是你能從portlet bean獲得這樣的URL嗎? – Buzzzz 2010-06-18 14:43:46