KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > sampleCluster2 > web > ReleaseServlet


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2005 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: ReleaseServlet.java,v 1.5 2005/04/28 12:17:19 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.sampleCluster2.web;
27
28 import java.io.IOException JavaDoc;
29
30 import javax.servlet.RequestDispatcher JavaDoc;
31 import javax.servlet.ServletException JavaDoc;
32 import javax.servlet.http.Cookie JavaDoc;
33 import javax.servlet.http.HttpServletRequest JavaDoc;
34 import javax.servlet.http.HttpServletResponse JavaDoc;
35 import javax.servlet.http.HttpSession JavaDoc;
36
37 import org.objectweb.util.monolog.api.BasicLevel;
38
39 /**
40  * @author goebelg Release an http session servlet
41  */

42 public class ReleaseServlet extends AbstractServlet {
43
44     /**
45      *
46      */

47     private static final long serialVersionUID = 1L;
48
49     /**
50      * doGet methode of the servlet
51      * @param req http servlet request
52      * @param res http servlet response
53      * @throws ServletException servlet exception
54      * @throws IOException io exception
55      */

56     public void doGet(HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) throws ServletException JavaDoc, IOException JavaDoc {
57
58         // Get the session object to invalidate it
59

60         HttpSession JavaDoc session = req.getSession(false);
61         String JavaDoc sessionToReleaseInfo = "no session to invalidate";
62         if (session != null) {
63             sessionToReleaseInfo = "session=" + session.getId() + " invalidated";
64             session.invalidate();
65         }
66         getLogger().log(BasicLevel.INFO, sessionToReleaseInfo);
67         req.setAttribute("sessionToReleaseInfo", sessionToReleaseInfo);
68
69         Cookie JavaDoc[] cookies = req.getCookies();
70         if (cookies != null) {
71             Cookie JavaDoc ck = null;
72             for (int i = 0; i < cookies.length; i++) {
73                 if (cookies[i].getName().equals("JSESSIONID")) {
74                     ck = (Cookie JavaDoc) cookies[i].clone();
75                     ck.setMaxAge(0);
76                     res.addCookie(ck);
77                 }
78             }
79         }
80
81         // --------------
82
// Write response
83
// --------------
84

85         RequestDispatcher JavaDoc disp = req.getRequestDispatcher("../jsp/releaseRsp.jsp");
86         disp.forward(req, res);
87
88         return;
89     }
90 }
Popular Tags