EN
Java - spring page URL redirection
9 points
In Spring Freamwork it is possible to make url redirection in following way.
RedirectionExampleController.java
file:
xxxxxxxxxx
1
package com.example;
2
3
import org.springframework.stereotype.Controller;
4
import org.springframework.web.bind.annotation.RequestMapping;
5
import org.springframework.web.bind.annotation.RequestMethod;
6
import org.springframework.web.bind.annotation.ResponseBody;
7
8
9
public class RedirectionExampleController {
10
11
value = "/redirect-to-my-final-page", method = RequestMethod.GET) (
12
public String redirectToMyFinalPage() {
13
return "redirect:/my-final-page";
14
}
15
16
value = "/my-final-page", method = RequestMethod.GET) (
17
18
public String myFinalPage() {
19
return "This is my final page.";
20
}
21
}
Running:
- Run server, e.g. on
localhost:8080
- Open in browser following link:
http://localhost:8080/redirect-to-my-final-page
Result:
Note: web page should be redirected to
http://localhost:8080/my-final-page
.