01: package com.mockrunner.example.servlet;
02:
03: import java.io.IOException;
04:
05: import javax.servlet.ServletException;
06: import javax.servlet.http.HttpServlet;
07: import javax.servlet.http.HttpServletRequest;
08: import javax.servlet.http.HttpServletResponse;
09:
10: /**
11: * This example servlet invalidates the session and redirects
12: * to a goodbye page when the user clicks the logout button
13: * (i.e. the request contains a parameter <i>logout=true</i>).
14: * Check out {@link LogoutServletTest}
15: * to see how to test this simple servlet.
16: */
17: public class LogoutServlet extends HttpServlet {
18: public void doGet(HttpServletRequest request,
19: HttpServletResponse response) throws ServletException,
20: IOException {
21: doPost(request, response);
22: }
23:
24: public void doPost(HttpServletRequest request,
25: HttpServletResponse response) throws ServletException,
26: IOException {
27: String logout = request.getParameter("logout");
28: if (null != logout) {
29: request.getSession().invalidate();
30: request.getRequestDispatcher("/html/goodbye.html").forward(
31: request, response);
32: }
33: }
34: }
|