9.5.1 Porlet 之间的通信方式-HttpSession
(1)portletA jsp页面设置表单
<%@page import="com.liferay.portal.kernel.portlet.LiferayWindowState" %>
<%@page import="com.liferay.portal.util.PortalUtil" %>
<%@page import="com.liferay.portal.model.User" %>
<%@page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defin eObjects/>
<portlet:actionURL var="updateForm" name="sendata"></portlet:actionURL>
<form action="<%=updateForm%>&urlparam=urlabc" method="post" name="<portlet:namespace/>form" >
用户名:<input type="text" name="id" id="<portlet:namespace/>userName">
<input type="submit" οnclick="<portlet:namespace/>save()">
</form>
(2)portletA 用 httpsession 设置值
public class PortletA extends MVCPortlet {
@Override
public void doView(RenderRequest renderRequest,
RenderResponse renderResponse) throws IOException, PortletException {
super.doView(renderRequest, renderResponse);
}
public void sendata(ActionRequest actionRequest,
ActionResponse actionResponse) throws IOException, PortletException {
String id = ParamUtil.getString(actionRequest, "id");
// 方式2 httpsession begin
HttpServletRequest servletRequest = PortalUtil.getHttpServletRequest(actionRequest);
servletRequest.getSession().setAttribute("sid", id);
// httpsession end
}
}
(3)portletB jsp 接收 Sid
<%@page import="com.liferay.portal.kernel.portlet.LiferayWindowState" %>
<%@page import="com.liferay.portal.util.PortalUtil" %>
<%@page import="com.liferay.portal.model.User" %>
<%@page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defineObjects/>
HTTPSession接收SID:${sid}