KickJava   Java API By Example, From Geeks To Geeks.

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


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.servlet.ServletException JavaDoc;
16 import javax.servlet.http.HttpServlet JavaDoc;
17 import javax.servlet.http.HttpServletRequest JavaDoc;
18 import javax.servlet.http.HttpServletResponse JavaDoc;
19 import javax.servlet.http.HttpSession JavaDoc;
20
21 /**
22  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
23  * @version $Revision: 1.2 $
24  */

25 public class CrossContextSessionServlet extends HttpServlet JavaDoc
26 {
27
28    protected void doGet(HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc resp) throws ServletException JavaDoc, IOException JavaDoc
29    {
30       doPost(req, resp);
31    }
32
33    protected void doPost(HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc resp) throws ServletException JavaDoc, IOException JavaDoc
34    {
35       HttpSession JavaDoc session = req.getSession();
36       String JavaDoc id = session.getId();
37       session.setAttribute("fromServlet", "fromServlet");
38
39       resp.setContentType("text/html");
40       PrintWriter JavaDoc writer = resp.getWriter();
41       writer.print("<html><body>");
42       writer.print("session ID " + id + "<br/>");
43       for (Enumeration JavaDoc e = session.getAttributeNames();e.hasMoreElements();)
44       {
45          String JavaDoc key = (String JavaDoc)e.nextElement();
46          writer.print(key + " = " + session.getAttribute(key) + "<br/>");
47       }
48       writer.print("</body></html>");
49       writer.close();
50    }
51
52 }
53
Popular Tags