Paulius Matulionis
Paulius Matulionis

Reputation: 23415

Spring MVC navigation path

I have a problem when trying to make some simple navigation in spring mvc. I have a navigation controller:

@Controller
@RequestMapping("/secure")
public class NavigationController {

    @RequestMapping("/operation")
    public String processOperationPage() {
        //Some logic goes here
        return "corpus/operation";
    }

    @RequestMapping("/configuration")
    public String processConfigurationPage() {
        //Some logic goes here
        return "corpus/configuration";
    }

}

and there is my links to reach that controller:

<a href="secure/operation.htm">Operation</a>
<a href="secure/configuration.htm">Configuration</a>

When the first time the link is clicked everything is OK. In the browser I see the normal path as I am expecting. For e.g: http://localhost/obia/secure/configuration.htm. But if I am at this page, and from this page I want to reach operation.htm when I click the operation link the path becomes like this: http://localhost/obia/secure/secure/operation.htm.

The secure appears two times. How can I solve this problem?

Upvotes: 0

Views: 2867

Answers (4)

user1359537
user1359537

Reputation: 26

Responder above has one correct answer in using c:url to generate an absolute URL. However, there are situations where the JSTL doesn't know the URL base correctly because of a firewall configuration. In that case, you can use a relative URL, but it has to know where you're starting from. i.e. on the page obia/secure/operation.htm, the url would be ../secure/configuration.htm, or just configuration.htm. The dot dot means to traverse up one level.

Upvotes: 0

Pau Kiat Wee
Pau Kiat Wee

Reputation: 9505

If you are using JSP, use JSTL instead:

<c:url value="/secure/operation.htm" />

Remember include taglib in JSP file:

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

By using JSTL, you can avoid to change the URL once the app is deploy to different context such as http://host/ and http://host/myapp

The first one will generate http://host/secure/operation.htm and second one will generate http://host/myapp/secure/operation.htm for you.

Upvotes: 5

yatul
yatul

Reputation: 1111

Change your URL from relative or calculate relative URL dinamically depending on current page. E.g. you can change your URL to host-based:

 
       <a href="/obia/secure/operation.htm">Operation</a>
       <a href="/obia/secure/configuration.htm">Configuration</a>
    

Upvotes: 2

user684934
user684934

Reputation:

Your links are relative. Adding a slash in front of them will fix it.

Upvotes: 5

Related Questions