2

It is simple page redirection example.When i click on it's button redirect page, it,s not working.It shows page not found.

final.jsp

<body>

    <h2>Redirected Page</h2>

</body>

HelloController.java

 @Controller 
 public class HelloController {

 @RequestMapping(value = "/", method = RequestMethod.GET)
 public String index(Model m) {
    return "index";
}

@RequestMapping(value = "/redirect", method = RequestMethod.GET)
public String redirect() {

    return "redirect:finalPage";
}

@RequestMapping(value = "/finalPage", method = RequestMethod.GET)
public String finalPage(Model m) {

    return "final";
}

index.jsp

<body>
    <h2>Spring Page Redirection</h2>
    <p>Click below button to redirect the result to new page</p>
    <form:form method="GET" action="/finalPage">
        <table>
            <tr>
                <td>
                    <input type="submit" value="Redirect Page"/>
                </td>
            </tr>
        </table>  
    </form:form>
</body>

web.xml

lavi
  • 65
  • 8

3 Answers3

1

Missed / in redirect:finalpage. It should be something like this

@RequestMapping(value = "/redirect", method = RequestMethod.GET)
public String redirect() {

    return "redirect:/finalPage";
}

But from where you are calling /redirect ?

Aditya Khajuria
  • 351
  • 1
  • 7
  • 19
1

The returned redirect string is wrong, try: "redirect:/finalPage"

dimitrisli
  • 20,895
  • 12
  • 59
  • 63
0

Please also have a look here. Basically, you need to have a UrlBasedViewResolver subclass in your project and have the final view in there, if it's not in root.

Community
  • 1
  • 1
Turbut Alin
  • 2,568
  • 1
  • 21
  • 30