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

com.mockrunner.example.servlet.LogoutServlet Maven / Gradle / Ivy

There is a newer version: 2.0.7
Show newest version
package com.mockrunner.example.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * This example servlet invalidates the session and redirects
 * to a goodbye page when the user clicks the logout button
 * (i.e. the request contains a parameter logout=true).
 * Check out {@link LogoutServletTest}
 * to see how to test this simple servlet.
 */
public class LogoutServlet extends HttpServlet
{
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
        doPost(request, response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
        String logout = request.getParameter("logout");
        if(null != logout)
        {
            request.getSession().invalidate();
            request.getRequestDispatcher("/html/goodbye.html").forward(request, response);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy