package de.hsel.spm.baudas.web; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; /** * Servlet implementation class LoginServlet. * * @author Edgar Schkrob */ @WebServlet("/login") public class LoginServlet extends HttpServlet { private final String password = "SPM2019SS"; /** * This is a Servlet that manages the Login and creates Sessions. * @param request This parameter provides access to everything the code needs to work. * @param response This parameter provides access to everything the code needs to issue a response. * @throws ServletException Defines a general exception a servlet can throw when it encounters difficulty. * @throws IOException Signals that an I/O exception of some sort has occurred. This class is the general class of exceptions produced by failed or interrupted I/O operations. */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (this.password.equals(password)) { HttpSession newSession = request.getSession(true); newSession.setAttribute("authentication", true); newSession.setMaxInactiveInterval(5*60*60); //setting session to expiry in 5 hours response.sendRedirect("index.jsp"); } else { RequestDispatcher rd = getServletContext().getRequestDispatcher("/login.html"); PrintWriter out = response.getWriter(); out.println("Das eingegebene Passwort ist falsch."); rd.include(request, response); } } }