KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > test > portlet > CrossContextSessionPortlet


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.test.portlet;
10
11 import java.io.IOException JavaDoc;
12 import java.io.PrintWriter JavaDoc;
13 import java.util.Enumeration JavaDoc;
14
15 import javax.portlet.GenericPortlet;
16 import javax.portlet.PortletException;
17 import javax.portlet.PortletSecurityException;
18 import javax.portlet.PortletSession;
19 import javax.portlet.RenderRequest;
20 import javax.portlet.RenderResponse;
21
22 /**
23  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
24  * @version $Revision: 1.2 $
25  */

26 public class CrossContextSessionPortlet extends GenericPortlet
27 {
28    protected void doView(RenderRequest req, RenderResponse resp) throws PortletException, PortletSecurityException, IOException JavaDoc
29    {
30       PortletSession session = req.getPortletSession();
31       String JavaDoc id = session.getId();
32       session.setAttribute("fromPortlet", "fromPortlet");
33
34       resp.setContentType("text/html");
35       PrintWriter JavaDoc writer = resp.getWriter();
36       writer.print("session ID " + id + "<br/>");
37       writer.print("<a HREF=\"" + req.getContextPath() + "/ccs\">visit</a> servlet on other context<br/>");
38       for (Enumeration JavaDoc e = session.getAttributeNames(PortletSession.PORTLET_SCOPE);e.hasMoreElements();)
39       {
40          String JavaDoc key = (String JavaDoc)e.nextElement();
41          writer.print(key + " = " + session.getAttribute(key, PortletSession.PORTLET_SCOPE) + "<br/>");
42       }
43       for (Enumeration JavaDoc e = session.getAttributeNames(PortletSession.APPLICATION_SCOPE);e.hasMoreElements();)
44       {
45          String JavaDoc key = (String JavaDoc)e.nextElement();
46          writer.print(key + " = " + session.getAttribute(key, PortletSession.APPLICATION_SCOPE) + "<br/>");
47       }
48       writer.close();
49    }
50 }
51
Popular Tags