Simplified way to do it...
Create 2 portlets Test1 and Test2 in Eclipse
1.
In first portlet Test1 - view.jsp
<jsp:useBean class="java.lang.String" id="submitURL" scope="request" />
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defineObjects />
This is the <b>Test</b> portlet.
<form action="/WEB-INF/html/test2.jsp" method="post">
<input type="submit" button="submit" value="submit" />
</form>
2.
a
Set the Jsp Portlet Class in portlet.xml
eg.
<portlet-name>Test</portlet-name>
<display-name>Test</display-name>
<portlet-class>com.liferay.TestPortlet(this you have to change in your code)</portlet-class>
<init-param>
<name>view-jsp</name>
b
Create a new class file of the first portlet
package com.liferay;
import java.io.IOException;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.PortletMode;
import javax.portlet.PortletPreferences;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.PortletURL;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.PortletSession;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletResponse;
import com.liferay.portal.util.PortalUtil;
public class TestPortlet extends GenericPortlet {
public void init() throws PortletException {
editJSP = getInitParameter("edit-jsp");
viewJSP = getInitParameter("view-jsp");
}
public void doView(RenderRequest renderRequest,
RenderResponse renderResponse) throws IOException, PortletException {
PortletURL submit = renderResponse.createActionURL();
submit.setParameter("submit", "submit");
renderRequest.setAttribute("submitURL", submit.toString());
include(viewJSP, renderRequest,
renderResponse);
}
public void processAction(ActionRequest actionRequest,
ActionResponse actionResponse) throws IOException, PortletException {
System.out.println("hi");
HttpServletRequest diffReq = PortalUtil.getHttpServletRequest(actionRequest);
HttpSession hs = diffReq.getSession(true);;
hs.setAttribute("LIFERAY_SHARED_test","test");
System.out.println(hs.getId());
actionResponse.sendRedirect("http://localhost:8082/web/guest/page2");
// actionResponse.setPortletMode(PortletMode.VIEW);
}
protected void include(String path, RenderRequest renderRequest,
RenderResponse renderResponse) throws IOException, PortletException {
PortletRequestDispatcher portletRequestDispatcher = getPortletContext()
.getRequestDispatcher(path);
if (portletRequestDispatcher == null) {
} else {
portletRequestDispatcher.include(renderRequest, renderResponse);
}
}
protected String editJSP;
protected String viewJSP;
}
2.
Now go to Second Portlet-view.jsp
<jsp:useBean id="bean1" class="java.lang.String" scope="request"/>
<%@page import="javax.servlet.http.HttpServletRequest"%>
<%@page import="javax.servlet.http.HttpServletResponse"%>
<%@page import="javax.servlet.http.HttpSession"%>
<%@ page import="com.liferay.portal.util.PortalUtil" %>
<%@page import="java.util.*" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defineObjects />
This is the <b>First Portlet</b> portlet.
Hello
<%
HttpServletRequest convertReq = PortalUtil.getHttpServletRequest(renderRequest);
HttpSession hs = convertReq.getSession();
String sessionid = hs.getId();
HttpSession hs1 =request.getSession();
String sessionid1=hs1.getId();
String name1="";
%>
<%=sessionid %>
<%=sessionid1 %>
<%
if(hs.getAttribute("LIFERAY_SHARED_test")!=null){
name1=hs.getAttribute("LIFERAY_SHARED_test").toString();}
else{
name1="Empty";
}
%>
wow<%=name1 %>
<%
Enumeration e = hs.getAttributeNames();
while (e.hasMoreElements()) {
String name = (String)e.nextElement();
String value = hs.getAttribute(name).toString();
System.out.println("name is: " + name + " value is: " + value);
}
%>
4. Now in liferay-portlet.xml of both the portlets set <private-session-attributes>false</private-session-attributes>
eg...
<icon>/icon.png</icon>
<private-session-attributes>false</private-session-attributes>
<header-portlet-css>/css/main.css</header-portlet-css>
<footer-portlet-javascript>/js/main.js</footer-portlet-javascript>
<css-class-wrapper>Test-portlet</css-class-wrapper>
5. Start Liferay.Deploy both the portlets one on first page and second one on the other page
Create 2 portlets Test1 and Test2 in Eclipse
1.
In first portlet Test1 - view.jsp
<jsp:useBean class="java.lang.String" id="submitURL" scope="request" />
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defineObjects />
This is the <b>Test</b> portlet.
<form action="/WEB-INF/html/test2.jsp" method="post">
<input type="submit" button="submit" value="submit" />
</form>
2.
a
Set the Jsp Portlet Class in portlet.xml
eg.
<portlet-name>Test</portlet-name>
<display-name>Test</display-name>
<portlet-class>com.liferay.TestPortlet(this you have to change in your code)</portlet-class>
<init-param>
<name>view-jsp</name>
b
Create a new class file of the first portlet
package com.liferay;
import java.io.IOException;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.PortletMode;
import javax.portlet.PortletPreferences;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.PortletURL;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.PortletSession;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletResponse;
import com.liferay.portal.util.PortalUtil;
public class TestPortlet extends GenericPortlet {
public void init() throws PortletException {
editJSP = getInitParameter("edit-jsp");
viewJSP = getInitParameter("view-jsp");
}
public void doView(RenderRequest renderRequest,
RenderResponse renderResponse) throws IOException, PortletException {
PortletURL submit = renderResponse.createActionURL();
submit.setParameter("submit", "submit");
renderRequest.setAttribute("submitURL", submit.toString());
include(viewJSP, renderRequest,
renderResponse);
}
public void processAction(ActionRequest actionRequest,
ActionResponse actionResponse) throws IOException, PortletException {
System.out.println("hi");
HttpServletRequest diffReq = PortalUtil.getHttpServletRequest(actionRequest);
HttpSession hs = diffReq.getSession(true);;
hs.setAttribute("LIFERAY_SHARED_test","test");
System.out.println(hs.getId());
actionResponse.sendRedirect("http://localhost:8082/web/guest/page2");
// actionResponse.setPortletMode(PortletMode.VIEW);
}
protected void include(String path, RenderRequest renderRequest,
RenderResponse renderResponse) throws IOException, PortletException {
PortletRequestDispatcher portletRequestDispatcher = getPortletContext()
.getRequestDispatcher(path);
if (portletRequestDispatcher == null) {
} else {
portletRequestDispatcher.include(renderRequest, renderResponse);
}
}
protected String editJSP;
protected String viewJSP;
}
2.
Now go to Second Portlet-view.jsp
<jsp:useBean id="bean1" class="java.lang.String" scope="request"/>
<%@page import="javax.servlet.http.HttpServletRequest"%>
<%@page import="javax.servlet.http.HttpServletResponse"%>
<%@page import="javax.servlet.http.HttpSession"%>
<%@ page import="com.liferay.portal.util.PortalUtil" %>
<%@page import="java.util.*" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defineObjects />
This is the <b>First Portlet</b> portlet.
Hello
<%
HttpServletRequest convertReq = PortalUtil.getHttpServletRequest(renderRequest);
HttpSession hs = convertReq.getSession();
String sessionid = hs.getId();
HttpSession hs1 =request.getSession();
String sessionid1=hs1.getId();
String name1="";
%>
<%=sessionid %>
<%=sessionid1 %>
<%
if(hs.getAttribute("LIFERAY_SHARED_test")!=null){
name1=hs.getAttribute("LIFERAY_SHARED_test").toString();}
else{
name1="Empty";
}
%>
wow<%=name1 %>
<%
Enumeration e = hs.getAttributeNames();
while (e.hasMoreElements()) {
String name = (String)e.nextElement();
String value = hs.getAttribute(name).toString();
System.out.println("name is: " + name + " value is: " + value);
}
%>
4. Now in liferay-portlet.xml of both the portlets set <private-session-attributes>false</private-session-attributes>
eg...
<icon>/icon.png</icon>
<private-session-attributes>false</private-session-attributes>
<header-portlet-css>/css/main.css</header-portlet-css>
<footer-portlet-javascript>/js/main.js</footer-portlet-javascript>
<css-class-wrapper>Test-portlet</css-class-wrapper>
5. Start Liferay.Deploy both the portlets one on first page and second one on the other page