1

The incoming request URL looks like: /{root}/Details/View/{id}. I have a servlet DetailsController which based on if a person is logged in or not will show either the "Edit" view or the "Details" view:

if (user != null) {
    detailsViewModel.setUser((User) user);
    getServletContext().getRequestDispatcher("/edit.jsp").forward(request, response);
} else {
    getServletContext().getRequestDispatcher("/details.jsp").forward(request, response);
}

In the edit view there is a form that has an action="Update" and I just want it to go to the UpdateController on /{root}/Update but it's trying to go /{root}/Details/View/{id}/Update. I've set the context root but to avail.

If I put action="/Update", it tries to go localhost:8080/Update without the root. Is this because I am using the forward? How can I fix this? Let me know if I'm missing details you need.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Sara
  • 612
  • 5
  • 21

1 Answers1

2

You need to prepend the context path in the form action URL with help of HttpServletRequest#getContextPath() in EL.

<form action="${pageContext.request.contextPath}/Update">

This way it becomes "/{root}/Update".

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555