Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect to different URL outside project from Controller

How can i redirect to different url eg: yahoo.com,hotmail.com from my controller i am using Spring 3.0 and using config and not annotations.

one thing i forgot to mention is the url will be user input so cannot add it in the config

Thanks Gauls

like image 630
Gauls Avatar asked Nov 19 '10 11:11

Gauls


People also ask

How we can redirect to another page or controller in Spring MVC?

We can use a name such as a redirect: http://localhost:8080/spring-redirect-and-forward/redirectedUrl if we need to redirect to an absolute URL.

How do I redirect a URL to another URL in Java?

The sendRedirect() method of HttpServletResponse interface can be used to redirect response to another resource, it may be servlet, jsp or html file. It accepts relative as well as absolute URL. It works at client side because it uses the url bar of the browser to make another request.

How do I redirect a URL in spring boot RestController?

@RestController public class RedirectController { @RequestMapping("/redirect") public String redirect() { return "redirect:/other/controller/"; } } and if we will try to access that url curl localhost:8080/redirect we will simply see redirect:/other/controller/ string as result.

What is RedirectView?

public class RedirectView extends AbstractUrlBasedView implements SmartView. View that redirects to an absolute, context relative, or current request relative URL. The URL may be a URI template in which case the URI template variables will be replaced with values available in the model.


1 Answers

You can use redirect: prefix in the controller method.

public String method(){
   return "redirect:http://yahoo.com"
}

More info in the section 13.5.3.2 of the spring documentation

like image 53
Javi Avatar answered Sep 30 '22 06:09

Javi