Liferay通信-PortletSession

编写Portlet组件A

  1. 建立mvc类型的Portlet模块
  2. 编写后台处理逻辑
    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);
    	}
    }
    
  3. 编写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

  1. 建立mvc类型的Portlet模块
  2. 编写后台处理逻辑
    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);
    	}
    }
    
  3. 编写jsp页面代码片段
    <b>显示A中提交的用户名:${sessionUsername}</b>
    
上一篇:Vue 报错'scope' is defined but never used解决方法总结


下一篇:tensorflow实现resnet50(训练+测试+模型转换)