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

com.alachisoft.ncache.web.examples.DebugServlet Maven / Gradle / Ivy

The newest version!
package com.alachisoft.ncache.web.examples;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class DebugServlet extends HttpServlet
{
    /**
     * Processes requests for both HTTP
     * GET and
     * POST methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        String op = request.getParameter("operation");
        if (op == null)
        {
            op = "";
        }
        HttpSession session = null;
        String text = "Welcome - Session Information 
"; if (op.equalsIgnoreCase("invalidate")) { session = request.getSession(false); if (session != null) { session.invalidate(); text += "Session Invalidated " + new Date(); } } else if (op.equalsIgnoreCase("create")) { session = request.getSession(); text += "Session Created " + new Date(); } text += "
"; if (!op.equalsIgnoreCase("norequest")) { session = request.getSession(false); } if (op.equalsIgnoreCase("timeout") && session != null) { try { int val = Integer.parseInt(request.getParameter("value")); session.setMaxInactiveInterval(val); } catch (Exception ex) { } } text += "Now is " + new Date() + "
"; if (session == null) { text += "No valid session associated with request"; } else { text += "

"; text += "Session ID:" + session.getId() + "
"; text += "Creation Time:" + new Date(session.getCreationTime()) + "
"; text += "Last Accessed:" + new Date(session.getLastAccessedTime()) + "
"; text += "Is New : " + session.isNew() + "
"; text += "Maximum Inactive Interval : " + session.getMaxInactiveInterval() + "
"; text += "

"; } try { out.println(""); out.println(""); out.println("Servlet DebugServlet"); out.println(""); out.println(""); out.println(text); out.println(""); out.println(""); } finally { out.close(); } } // /** * Handles the HTTP * GET method. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } /** * Handles the HTTP * POST method. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } /** * Returns a short description of the servlet. * * @return a String containing servlet description */ public String getServletInfo() { return "Short description"; } // }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy