All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jboss.mod_cluster.MyCount Maven / Gradle / Ivy

There is a newer version: 1.3.21.Final
Show newest version
/*
 *  Copyright(c) 2006 Red Hat Middleware, LLC,
 *  and individual contributors as indicated by the @authors tag.
 *  See the copyright.txt in the distribution for a
 *  full listing of individual contributors.
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library in the file COPYING.LIB;
 *  if not, write to the Free Software Foundation, Inc.,
 *  59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 *
 * @author Jean-Frederic Clere
 * @version $Revision: 420067 $, $Date: 2006-07-08 09:16:58 +0200 (sub, 08 srp 2006) $
 */

import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;



/**
 * Example servlet showing cookies handling (counter).
 *
 */

public class MyCount extends HttpServlet {

    public void init(ServletConfig config) throws ServletException {
        String swait = config.getInitParameter("wait");
        int wait = 0;
        if (swait != null) {
            Integer iwait = new Integer(swait);
            wait = iwait.intValue();
        }

        if (wait != 0) {
            Thread me = Thread.currentThread();
            try {
                me.sleep(wait);
            } catch(Exception e) {
                throw new ServletException("sleep interrupted");
            }
        }
    }

    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
    {
        response.setContentType("text/html");

        PrintWriter out = response.getWriter();
        out.println("");
        out.println("");
        out.println("");

        String title = "sessions.title";
        out.println("" + title + "");
        out.println("");
        out.println("");

        out.println("

" + title + "

"); HttpSession session = request.getSession(false); Integer ii = new Integer(0); if (session == null) { // Create it. out.println("create"); session = request.getSession(true); session.setAttribute("count", ii); } out.println("sessions.id " + session.getId()); out.println("
"); out.println("sessions.created "); out.println(new Date(session.getCreationTime()) + "
"); out.println("sessions.lastaccessed "); out.println(new Date(session.getLastAccessedTime())); out.println("sessions.count "); out.println(session.getAttribute("count")); ii = (Integer) session.getAttribute("count"); int i = 0; if (ii != null) i = ii.intValue(); i++; ii = new Integer(i); // JAVA5 : ii.valueOf(i); session.setAttribute("count", ii); out.println("

"); out.println("sessions.data
"); Enumeration names = session.getAttributeNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); String value = session.getAttribute(name).toString(); out.println(name + " = " + value + "
"); // response.addHeader(name, value); } out.println("

"); out.print("

"); out.println("sessions.dataname"); out.println(""); out.println("
"); out.println("sessions.datavalue"); out.println(""); out.println("
"); out.println(""); out.println("
"); out.println("

GET based form:
"); out.print("

"); out.println("sessions.dataname"); out.println(""); out.println("
"); out.println("sessions.datavalue"); out.println(""); out.println("
"); out.println(""); out.println("
"); out.print("

URL encoded "); out.println(""); out.println(""); out.println(""); out.println(""); /* Use headers */ response.setHeader("RequestedSessionId", request.getRequestedSessionId()); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { doGet(request, response); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy