I am experiencing problems with Spring MVC @RequestMapping
s 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?
I think what you need is "redirect:/preferences/email"