Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect in Play Framework?

When I call other action in one action, it also display itself template, in Play 1.1 RC and when I Redirect("...url") but it does not work, is there someone that can help me?

like image 569
chenwenfeng Avatar asked Nov 28 '22 18:11

chenwenfeng


2 Answers

Just to add to the answers above, here's how you redirect to an external url:

public static void index() { redirect("http://geeks.aretotally.in"); }

like image 94
Felipe Oliveira Avatar answered Dec 05 '22 12:12

Felipe Oliveira


To redirect, you simply call the action. From the example in the documentation:

public static void show(Long id) {
    Article article = Article.findById(id);
    render(article);
}

public static void edit(Long id, String title) {
    Article article = Article.findById(id);
    article.title = title;
    article.save();
    show(id);
}

At the end of the edit action, the call to show(...) will cause a redirect on the client's browser as if they had hit the same URL that routes to the show method.

like image 30
Lawrence McAlpin Avatar answered Dec 05 '22 11:12

Lawrence McAlpin