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.

1 Answer 1

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:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.