Question

I am experiencing problems with Spring MVC @RequestMappings and redirects.

I have the following method in one of my controllers:

@RequestMapping(value = "/activateEmail/{token}", method = RequestMethod.GET, produces = "text/html")
    public String activateEmail(@PathVariable("token") String token) {
        preferencesService.activateEmail(token);
        signinService.signin(memberRepository.findByToken(token));
        return "redirect:preferences/email";//HERE
}

However, when the user is initially located at:

http://localhost:8080/bignibou/preferences/email

the above "redirect directive" redirects to:

http://localhost:8080/bignibou/activateEmail/preferences/email

Whereas I expected it to redirect me to:

http://localhost:8080/bignibou/preferences/email

In order for the desired effect to be achieved I had to resort to the following ugly hack:

return "redirect:../preferences/email";//HERE

Can anyone please suggest a better practice?

Was it helpful?

Solution

I think what you need is "redirect:/preferences/email"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top