Take the 2-minute tour ×

I have 2 tomcat instances. both are behind proxying apache httpds. my code in the Spring controller looks like this:

@RequestMapping(value = "/doSuperSexyStuff", method = RequestMethod.GET)
public String viewSuperSexyStuff() {
    return "redirect:/mySuperSexyStuff";

On my first tomcat installation on Windows I have somedomain1.dev redirected to http://localhost:8080/myapp and everything works flawlessly. redirect goes to http://somedomain1.dev/mySuperSexyStuff

On the other tomcat installation (which is on Linux) the redirect works relative to the context path and user end up at http://somedomain2.dev/myapp/mySuperSexyStuff which is obviously wrong.

What should I do for spring to ignore the context path and just redirect the user to where he "belongs"?

All URLs in my application are absolute(everything including links in jsps, redirect urls and all the places where links are used). I guess that's not the correct way to do stuff: if I have to implement HTTPS version of the site I'll be in trouble. So if you you think I must change something fundamentally in my approach please point me in the right direction.

share|improve this question

3 Answers 3

up vote 5 down vote accepted

Instead of returning a String, which is very inflexible, consider returning a View:

    public View viewSuperSexyStuff(){
    return new RedirectView("/mySuperSexyStuff");

The redirect view has a constructor which takes a boolean contextRelative so the following would do the opposite of the above:

return new RedirectView("/mySuperSexyStuff", true);

All your url's should be context relative unless you really them point off your site, so links to css, image assets etc. should in jsp's use <c:url /> tags to resolve paths.

share|improve this answer

One of the ways you can achieve this is to use your web application deployed to the root and not as context "myapp". This makes sense as you have separate domains configured. Just use put all your files on the tomcat root folder.

share|improve this answer

Spring documentation for MVC says that the path sould always be relative to your context path.

As far as I see you have two options:

  • Using an absolute path in your redirect like "http://somedomain...."

  • Check your configuration of the context path of the web application

Hope this helps a step further...

share|improve this answer

Your Answer


