前台jsp传参到后台portlet、以及两个portlet直接共享参数
角色:A.java B.java代表两个portlet a.jsp b.jsp代表两个portlet对应的jsp页面
方法一:
完成步骤:
前期准备工作
Portlet的注册如:
<portlet>
<description>用户管理.</description>
<portlet-name>UserPortlet</portlet-name>
<display-name>User Portlet</display-name>
<display-namexml:lang="zh">用户管理</display-name>
<portlet-class>com.mcbeath.portal.user.portlets.UserPortlet</portlet-class>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>VIEW</portlet-mode>
</supports>
<supported-locale>zh</supported-locale>
<portlet-info>
<title>用户管理</title>
<short-title>用户管理</short-title>
<keywords>用户管理</keywords>
</portlet-info>
<!-- 支持共享参数 -->
<supported-public-render-parameter>service-id</supported-public-render-parameter>r-parameter>
<!--然后,在最后面定义这个参数,写法是这样的:-->
<public-render-parameter>
<identifier>service-id</identifier>
<qnamexmlns:x="http://sun.com/params">x:service</qname>
</public-render-parameter>
</portlet>
1 a.jsp里面<ahref='${actionURL}?method=add'>
2 a.jsp顶部写:<%@tagliburi='/WEB-INF/tld/portlet.tld'prefix='portlet'%>
<portlet:actionURLvar="actionURL"portletMode="view"/>
3 在后台A.java portlet下面方法接收参数
publicvoid processAction(ActionRequest actionRequest, ActionResponseactionResponse)throws PortletException, IOException {
PortletSession session =actionRequest.getPortletSession();
String method =actionRequest.getParameter("method");
//将从前台拿到的参数存储到portlet的共享参数里面,参数名为service-id
actionResponse.setRenderParameter("service-id", method);
}
3 到跳转的那个B.java portlet里面获取参数
publicvoid doView(RenderRequest request, RenderResponse response )
throws PortletException, IOException{
String[] params =request.getParameterValues("service-id");
PortletSession session =request.getPortletSession();
//把A.java portlet里面的传过来的参数放到PortletSession中,好b.jsp页面获取
session.setAttribute("LAST_TYPED_CONTENTID", params) ;
normalView.include( request, response );
}
4 b.jsp页面接收参数
b.jsp页面顶部填写
<%@pagelanguage="java"session="true"
import="javax.portlet.PortletSession"%>
<%
PortletSession portletSession = renderRequest.getPortletSession();
String[] methods=(String[])portletSession.getAttribute("LAST_TYPED_CONTENTID");
%>