Skip to content

Package: FilterServlet

FilterServlet

nameinstructionbranchcomplexitylinemethod
FilterServlet()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
doGet(HttpServletRequest, HttpServletResponse)
M: 43 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
doPost(HttpServletRequest, HttpServletResponse)
M: 23 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 2001, 2023 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Distribution License v. 1.0, which is available at
6: * http://www.eclipse.org/org/documents/edl-v10.php.
7: *
8: * SPDX-License-Identifier: BSD-3-Clause
9: */
10:
11: package demo;
12:
13: import jakarta.servlet.ServletException;
14: import jakarta.servlet.http.HttpServlet;
15: import jakarta.servlet.http.HttpServletRequest;
16: import jakarta.servlet.http.HttpServletResponse;
17: import jakarta.servlet.http.HttpSession;
18:
19: import java.io.IOException;
20:
21: /**
22: * This servlet is used to determine whether the user is logged in before
23: * forwarding the request to the selected URL.
24: */
25: public class FilterServlet extends HttpServlet {
26:
27: /**
28: * This method handles the "POST" submission from two forms: the
29: * login form and the message compose form.
30: */
31: public void doPost(HttpServletRequest request,
32: HttpServletResponse response)
33: throws IOException, ServletException {
34:
35: String servletPath = request.getServletPath();
36: servletPath = servletPath.concat(".jsp");
37:
38: getServletConfig().getServletContext().
39: getRequestDispatcher("/" + servletPath).forward(request, response);
40: }
41:
42: /**
43: * This method handles the GET requests from the client.
44: */
45: public void doGet(HttpServletRequest request,
46: HttpServletResponse response)
47: throws IOException, ServletException {
48:
49: // check to be sure we're still logged in
50: // before forwarding the request.
51: HttpSession session = request.getSession();
52: MailUserBean mailuser = (MailUserBean) session.getAttribute("mailuser");
53: String servletPath = request.getServletPath();
54: servletPath = servletPath.concat(".jsp");
55:
56:• if (mailuser.isLoggedIn())
57: getServletConfig().getServletContext().
58: getRequestDispatcher("/" + servletPath).
59: forward(request, response);
60: else
61: getServletConfig().getServletContext().
62: getRequestDispatcher("/index.html").
63: forward(request, response);
64: }
65: }
66: