| 1 9 package org.jboss.portal.test.portlet; 10 11 import java.io.IOException ; 12 import java.io.PrintWriter ; 13 import java.util.Enumeration ; 14 15 import javax.servlet.ServletException ; 16 import javax.servlet.http.HttpServlet ; 17 import javax.servlet.http.HttpServletRequest ; 18 import javax.servlet.http.HttpServletResponse ; 19 import javax.servlet.http.HttpSession ; 20 21 25 public class CrossContextSessionServlet extends HttpServlet  26 { 27 28 protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException , IOException  29 { 30 doPost(req, resp); 31 } 32 33 protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException , IOException  34 { 35 HttpSession session = req.getSession(); 36 String id = session.getId(); 37 session.setAttribute("fromServlet", "fromServlet"); 38 39 resp.setContentType("text/html"); 40 PrintWriter writer = resp.getWriter(); 41 writer.print("<html><body>"); 42 writer.print("session ID " + id + "<br/>"); 43 for (Enumeration e = session.getAttributeNames();e.hasMoreElements();) 44 { 45 String key = (String )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 |