I am learning play framework and understand that I can map a request such as /manager/user
as:
GET /manage/:user Controllers.Application.some(user:String)
How would I map a request like /play/video?video_id=1sh1
?
I am learning play framework and understand that I can map a request such as /manager/user
as:
GET /manage/:user Controllers.Application.some(user:String)
How would I map a request like /play/video?video_id=1sh1
?
I'm not quite sure if I got what you meant if you meant just to map a url to function in controller the answer of biesior is perfect but if you mean submitting a form with get method like
and having the form's parameter in the url in the url-rewrited format like
There is no way to do that because that's http specs
I do often circumvent this limitation by getting the parameters in the first function in controller and then redirect them to another view just like the following
Then have whatever in the page2
And have this in the routes file :
I hope it'd help but I'm not sure that's the best practise
You have at least two possibilities, let's call them
approach1
andapproach2
.0
is good candidate, as it will be easiest to build some condition on top of it. Also it'stypesafe
, and pre-validates itself. I would recommend this solution at the beginning.String
so you need to parse it to integer and additionally validate if required.routes
:actions:
PS: LOL I just realized that you want to use String identifier... anyway both approaches will be similar :)
Ok so I just read up the documentation and what I understand is that you need to
And then in the controller call the getQueryString of the HttpRequest object
http://www.playframework.com/documentation/api/2.1.0/java/index.html
I would do it simply using:
And at controller you would of course have, something like:
Alternatively, you dont have to add
video_id:String
since play seems to treat parameters as String by default, so it also works like this (at least with newest play):Typing
localhost:9000/play/video?video_id=1sh1
to address bar should now you give view which prints:To add more parameters is simple, like this:
Controller:
Typing
localhost:9000/play/video?video_id=1as1&site=www.google.com&page=3
to address bar should now you give view which prints:You're welcome ^^.