/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package controller; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * * @author nim_13515091 */ @WebServlet(name = "LoginServlet", urlPatterns = {"/Login"}) public class LoginServlet extends HttpServlet { /** * Handles the HTTP <code>GET</code> method. * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String userPath = request.getServletPath(); // use RequestDispatcher to forward request internally String url = "/WEB-INF/view/login" + userPath + ".jsp"; try { request.getRequestDispatcher(url).forward(request, response); } catch (IOException | ServletException ex) { } } /** * Handles the HTTP <code>POST</code> method. * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String userPath = request.getServletPath(); // if addToCart action is called if (userPath.equals("/Login")) { // TODO: Implement add product to cart action // if updateCart action is called } // use RequestDispatcher to forward request internally String url = "/WEB-INF/view/login" + userPath + ".jsp"; try { request.getRequestDispatcher(url).forward(request, response); } catch (IOException | ServletException ex) { } } }