I'm working with Spring's annotations for the first time and I'm having some issues with the URL doubling up on subsequent hits of @RequestMapping
. I have the following snippet:
@Controller @RequestMapping("/login")
public class Login {
private LoginService loginService;
@Autowired
public Login(LoginService loginService){
this.loginService = loginService;
}
@RequestMapping(method=RequestMethod.GET)
public String setupLogin(){ return "login"; }
@RequestMapping(method=RequestMethod.GET, value="/retry")
public String setupLoginRetry(){ return "login"; }
@RequestMapping(method=RequestMethod.POST)
public String processLogin(@ModelAttribute("userName") String userName, @ModelAttribute("password") String password){
if (true) return "redirect:login/retry"; //hard-coded for example
return "redirect:home";
}
}
If I bring up the page and just hit the submit a bunch of times I get the following:
myApp/login
myApp/login/retry?userName=&password=
myApp/login/login // <-- this fails as it shouldn't be nesting logins
So obviously, I'm doing something wrong. My questions are:
1.) What can I do to prevent the parameters from showing up in the URL when it goes to retry? Edit: Removing this question - found the answer.
2.) Why does it start nesting logins and what is the proper way to declare this?
Any thoughts or assistance would be appreciated. Thanks!