KickJava   Java API By Example, From Geeks To Geeks.

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


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: CheckServlet.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
41  *
42  * Servlet which checks the HTTP session
43  */

44 public class CheckServlet extends AbstractServlet {
45
46     /**
47      *
48      */

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

58     public void doGet(HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) throws ServletException JavaDoc, IOException JavaDoc {
59
60         HttpSession JavaDoc session = req.getSession(false);
61
62         String JavaDoc sessionCheckInfo = "JSESSIONID cookie absent.";
63         Cookie JavaDoc[] cookies = req.getCookies();
64         if (cookies != null) {
65             for (int i = 0; i < cookies.length; i++) {
66                 if (cookies[i].getName().equals("JSESSIONID")) {
67                     sessionCheckInfo = "JSESSIONID cookie present.";
68                 }
69             }
70         }
71
72         getLogger().log(BasicLevel.INFO, sessionCheckInfo);
73         req.setAttribute("sessionCheckInfo", sessionCheckInfo);
74
75         // --------------
76
// Write response
77
// --------------
78
RequestDispatcher JavaDoc disp = req.getRequestDispatcher("../jsp/checkRsp.jsp");
79         disp.forward(req, res);
80
81         return;
82     }
83 }
Popular Tags