0

I have the following URL mapping in controller

@RequestMapping(value = "/additem.htm", method = RequestMethod.GET)
@RequestMapping(value = "/additem/fileupload.htm", method = RequestMethod.POST)

I click on page with href="additem.htm" and it goes to the controller with value="/additem.htm" above. I fill up form in that and submit the form.

The form gets posted to action="additem/fileupload.htm", which goes to the controller with value="/additem/fileupload.htm". Once i complete this fileupload controller and returns a jsp the browser urls turns to "http://localhost:8080/Dream/additem/fileupload.htm".

The problem is, when I again click on the first link with href="additem.htm", it is trying to search for controller with mapping like "additem/additem.htm".

Even when i hover over the link the browser is showing the url as http://localhost:8080/Dream/additem/additem.htm and it throws an error. How do i resolve this URL issue?

0

1 Answer 1

3

When you define a link in a jsp, use the c:url tag to generate urls relative to your app's context path:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<a href="<c:url value="/additem.htm" />">Click here</a>

It will prepend your application's context path to the href. It should generate:

<a href="/Dream/additem.htm">Click here</a>
Sign up to request clarification or add additional context in comments.

1 Comment

and take note of the leading slash in the value of the c:url. Without that, it'll be relative and you'll end up with just what you have now.

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.