Java - spring page URL redirection

6 points
Created by:

In Spring Freamwork it is possible to make url redirection in following way.

1. redirection:my_url prefix example file:

package com.example;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

public class RedirectionExampleController {

    @RequestMapping(value = "/redirect-to-my-final-page", 
        method = RequestMethod.GET)
    public String redirectToMyFinalPage() {
        return "redirect:/my-final-page";

    @RequestMapping(value = "/my-final-page", 
        method = RequestMethod.GET)
    public String myFinalPage() {
        return "This is my final page.";


  1. Run server, e.g. on localhost:8080
  2. Open in browser following link: http://localhost:8080/redirect-to-my-final-page


Note: web page should be redirected to http://localhost:8080/my-final-page.

2. References

  1. Redirecting - Spring Docs 

Checkout latest findings & news:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Rockstar community members
Thank you for great work 👍