Liferay通信-PortletSession
作者:互联网
编写Portlet组件A
- 建立mvc类型的Portlet模块
- 编写后台处理逻辑
public class PortalSessionAPortlet extends MVCPortlet { @ProcessAction(name ="update") public void update(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException { String username = ParamUtil.getString(actionRequest, "username") ; // 注意这里需要设置为APPLICATION_SCOPE,否则取不到 actionRequest.getPortletSession().setAttribute("sessionUsername", username, PortletSession.APPLICATION_SCOPE); } }
- 编写jsp页面代码片段
<portlet:actionURL var = "updateUrl" name ="update"/> <form method ="post" action ="${updateUrl}"> 用户名:<input type ="text" name ="<portlet:namespace/>username" /> <input type ="submit" value ="提交" /> </form>
编写Portlet组件B
- 建立mvc类型的Portlet模块
- 编写后台处理逻辑
public class PortalSessionBPortlet extends MVCPortlet { private Logger log = LoggerFactory.getLogger(PortalSessionBPortlet.class) ; @Override public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException { // 取值时也需要使用APPLICATION_SCOPE String sessionUsername = (String)renderRequest.getPortletSession() .getAttribute("sessionUsername", PortletSession.APPLICATION_SCOPE) ; log.info("======> sessionUsername :{}", sessionUsername); super.doView(renderRequest, renderResponse); } }
- 编写jsp页面代码片段
<b>显示A中提交的用户名:${sessionUsername}</b>
标签:Portlet,PortletSession,sessionUsername,通信,public,APPLICATION,SCOPE,编写,Liferay 来源: https://blog.csdn.net/yichengjie_c/article/details/118765853