[Play 2.4/2.5 Java] Getting context path

109 views
Skip to first unread message

Patrick Li

unread,
Feb 23, 2017, 8:02:01 PM2/23/17
to Play Framework
Hi all,

I have configured my Play app to run under a context path, e.g. /myapp, so the url will be something like http://app.host.com:9000/myapp. I have added the context path to application.conf's play.http.context parameter, and all works fine. Play will recognize the context path set and render pages accordingly.

My questions is, how do I get the context path both in code or in template? Essentially, the equivalent of servlet's request.getContextPath().

What I am trying to do is, manually construct a URL in the template, e.g. to post a form. I understand I can (and should) use Play's built-in reverse routing for it, but I have a special case where I need to manually construct the URL.

Thanks
Patrick

Igmar Palsenberg

unread,
Feb 24, 2017, 2:50:40 AM2/24/17
to Play Framework


Op vrijdag 24 februari 2017 02:02:01 UTC+1 schreef Patrick Li:
You should use the reverse router. You can fetch the play.http.context param yourself if you want / can't use the reverse route. @Inject Configuration on a controller, and either pass that, or fetch the value from the controller and pass that.



Igmar

Patrick Li

unread,
Feb 24, 2017, 1:47:18 PM2/24/17
to Play Framework
Thanks.
Reply all
Reply to author
Forward
0 new messages