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, 2021 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 java.io.*;
14: import jakarta.servlet.*;
15: import jakarta.servlet.http.*;
16:
17: /**
18: * This servlet is used to determine whether the user is logged in before
19: * forwarding the request to the selected URL.
20: */
21: public class FilterServlet extends HttpServlet {
22:
23: /**
24: * This method handles the "POST" submission from two forms: the
25: * login form and the message compose form.
26: */
27: public void doPost(HttpServletRequest request,
28:                  HttpServletResponse response)
29:                  throws IOException, ServletException {
30:
31:         String servletPath = request.getServletPath();
32:         servletPath = servletPath.concat(".jsp");
33:         
34:         getServletConfig().getServletContext().
35:          getRequestDispatcher("/" + servletPath).forward(request, response);
36: }
37:
38: /**
39: * This method handles the GET requests from the client.
40: */
41: public void doGet(HttpServletRequest request,
42:                  HttpServletResponse response)
43:                  throws IOException, ServletException {
44:
45:         // check to be sure we're still logged in
46:         // before forwarding the request.
47:         HttpSession session = request.getSession();
48:         MailUserBean mailuser = (MailUserBean)session.getAttribute("mailuser");
49:         String servletPath = request.getServletPath();
50:         servletPath = servletPath.concat(".jsp");
51:         
52:•        if (mailuser.isLoggedIn())
53:          getServletConfig().getServletContext().
54:                 getRequestDispatcher("/" + servletPath).
55:                 forward(request, response);
56:         else
57:          getServletConfig().getServletContext().
58:                 getRequestDispatcher("/index.html").
59:                 forward(request, response);
60: }
61: }
62: