0

I have a simple doGet method on a hyperlink to direct a view cart summary. It works if I run on the servlet the path is,

 http://localhost:9090/WebApp/view_cart

whereas if I run on the JSP page when I click the below hyperlink, The path is

<form method="GET"> <a href="view_cart"> view cart </a> </form>

http://localhost:9090/WebApp/frontend/view_cart

Here is a doGet method, how can I get the correct path to show the /view_cart page??

@WebServlet("/view_cart")
public class ViewCartServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public ViewCartServlet() {
        super();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        response.getWriter().append("Served at: ").append(request.getContextPath());
                    
        response.setContentType("text/html");

        String viewCart = "frontend/shopping_cart.jsp";
        RequestDispatcher rd = request.getRequestDispatcher(viewCart);
        rd.forward(request, response);    
    }

}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Stu_Dent
  • 370
  • 1
  • 4
  • 19

1 Answers1

1

Replace

<a href="view_cart">

with

<a href="/view_cart">

So that the path can become the-context-path/view_cart

Arvind Kumar Avinash
  • 71,965
  • 6
  • 74
  • 110