[2.0.2-java] How to route back to previous URL?

2,285 views
Skip to first unread message

Alex Hanschke

unread,
Jul 11, 2012, 7:16:17 AM7/11/12
to play-fr...@googlegroups.com
What is the most elegant way to route back to the client's previous page?

I'm thinking of an application which has a login form on every page and, at some point the client is required to login.
I then want to make sure the login action routes back to the page the user was on.
Any ideas?

Cheers,
Alex

Guillaume Bort

unread,
Jul 11, 2012, 8:25:20 AM7/11/12
to play-fr...@googlegroups.com
Just include the original URL in the login call. This is a pretty common solution.

/login?from=http://xxx


--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/IiuQh_K7e7kJ.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.



--
Guillaume Bort, http://guillaume.bort.fr

Alex Hanschke

unread,
Jul 11, 2012, 8:29:30 AM7/11/12
to play-fr...@googlegroups.com
Thanks Guillaume - just thought there could be a more sophisticated solution, but it'll do the work!


On Wednesday, July 11, 2012 2:25:20 PM UTC+2, Guillaume Bort wrote:
Just include the original URL in the login call. This is a pretty common solution.

/login?from=http://xxx

On Wed, Jul 11, 2012 at 1:16 PM, Alex Hanschke <alexander...@gmail.com> wrote:
What is the most elegant way to route back to the client's previous page?

I'm thinking of an application which has a login form on every page and, at some point the client is required to login.
I then want to make sure the login action routes back to the page the user was on.
Any ideas?

Cheers,
Alex

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/IiuQh_K7e7kJ.
To post to this group, send email to play-framework@googlegroups.com.
To unsubscribe from this group, send email to play-framework+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.

Gaëtan Renaudeau

unread,
Jul 11, 2012, 8:45:03 AM7/11/12
to play-fr...@googlegroups.com
You can also redirect to the referer URL assuming the browser will send this header,

I had this code for Play 1:

        try{ redirect(request.headers.get("referer").values.get(0)); } catch (Exception e) { redirect("/"); }

It should be difficult to port this for Play 2


2012/7/11 Alex Hanschke <alexander...@gmail.com>
To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/xX-VlDFpsOIJ.

To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.



--
Gaëtan Renaudeau, greweb.fr

Gaëtan Renaudeau

unread,
Jul 11, 2012, 8:46:29 AM7/11/12
to play-fr...@googlegroups.com
(ok my try catch was a bit wrong because it catch the Redirect exception, just to tell that you need to check if referer is available, but it should be easier with scala, in a functional way)

2012/7/11 Gaëtan Renaudeau <renaudea...@gmail.com>



--
Gaëtan Renaudeau, greweb.fr

C. Mundi

unread,
Jul 11, 2012, 11:02:30 AM7/11/12
to play-fr...@googlegroups.com

[I am learning play so I have not tried this.]

I know I should just embrace the web, but I believe that loading up the url with query strings is an ugly failure to separate concerns.  So the way I have handled this in other frameworks is to embed the original target (or referrer, or whatever the semantic destination should be) as a hidden field in the login form.  Then, when the user hits submit, my POST action reads the hidden field and does a redirect...assuming successful validation of course.

HTH,
Carlos

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/IiuQh_K7e7kJ.

deepak menon

unread,
Mar 13, 2014, 9:54:53 AM3/13/14
to play-fr...@googlegroups.com
I am not sure if i am right but when we try to access the original url directly , we will be taken to the login page and the login page inturn has a reference to the original url (i happened to see in my web application). In that case all you have to do is add the window href location to the form submit action.
Reply all
Reply to author
Forward
0 new messages