Change URL in spring mvc

java, spring, spring-mvc

Solution

Your form should thus have `login` as its action, and the method implementing this action should redirect to welcome if the login is successful.

@RequestMapping(value = "/login", method = ResquestMethod.POST)
public String handleLogin([...]) {
    ...
    if (successful) {
        return "redirect:/welcome"
    }
}

Problem

I have a login form like this in URL `http://localhost:8080/myproject/login` : ``` <form:form method="POST" modelAttribute="auth" action="welcome" id="formlogin"> [...] </form:form> ``` and a controller like this: ``` @RequestMapping(value = "/welcome") public String welcome([...]) { [...] if(logins.size() != 1) { return "login"; } [...] return "welcome"; } ``` the problem is when the login is incorrect i got this URL `http://localhost:8080/myproject/welcome` but i want to get `http://localhost:8080/myproject/login` and get `welcome` just in case the login is correct. 1st UPDATE In my case the best way to use ``` return "redirect:/login" ``` but before i have to add a attribute like this ``` model.put("errorlogin", true); ``` To handle this ``` <c:if test="${ errorlogin == true }"> <label class="loginerror">Login Error</label> </c:if> ``` But the error message doesn't display and instead i got this URL ``` http://localhost:8080/pagesjaunes/login?errorlogin=true ``` I set a Attribute and I get a Parameter. 2nd UPDATE i fixed the problem with this : ``` <c:if test="${ param.errorlogin == true }"> <label class="loginerror">Login Error</label> </c:if> ```

Original source