You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Andrea Del Bene <an...@gmail.com> on 2013/04/03 14:44:05 UTC
Best way to get the base application URL?
Hi,
do you know the best way to get the base URL for our Wicket application?
For example
"http://www.mysite.com/myapplication"
I'm using the following code at the moment:
protected CharSequence extractBaseUrl(Request request) {
Url originalUrl = request.getOriginalUrl();
CharSequence baseUrl = originalUrl.getProtocol() + "://" +
originalUrl.getHost() +
":" + originalUrl.getPort() +
request.getContextPath();
return baseUrl;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Best way to get the base application URL?
Posted by Andrea Del Bene <an...@gmail.com>.
Thank you Dan! Your code works perfectly!
> Url relative = Url.parse(getRequest().getContextPath());
> String full = getRequestCycle().getUrlRenderer().renderFullUrl(relative);
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Best way to get the base application URL?
Posted by Dan Retzlaff <dr...@gmail.com>.
How about:
Url relative = Url.parse(getRequest().getContextPath());
String full = getRequestCycle().getUrlRenderer().renderFullUrl(relative);
Dan
On Wed, Apr 3, 2013 at 5:44 AM, Andrea Del Bene <an...@gmail.com>wrote:
> Hi,
>
> do you know the best way to get the base URL for our Wicket application?
> For example
>
> "http://www.mysite.com/**myapplication<http://www.mysite.com/myapplication>
> "
>
> I'm using the following code at the moment:
>
>
> protected CharSequence extractBaseUrl(Request request) {
> Url originalUrl = request.getOriginalUrl();
> CharSequence baseUrl = originalUrl.getProtocol() + "://" +
> originalUrl.getHost() +
> ":" + originalUrl.getPort() +
> request.getContextPath();
>
>
> return baseUrl;
> }
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<us...@wicket.apache.org>
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: Best way to get the base application URL?
Posted by Paul Bors <pa...@bors.ws>.
I've used this to show the full URL to one of my pages as the model object
of a hyperlink including the paramaters (since I have a bookmarkable page):
HttpServletRequest httpReq =
(HttpServletRequest)((WebRequest)RequestCycle.get().getRequest()).getContainerRequest();
String relativePagePath = urlFor(DownloadMSIPage.class, params).toString();
String url =
RequestUtils.toAbsolutePath(httpReq.getRequestURL().toString(),
relativePagePath);
~ Thank you,
Paul Bors
On Wed, Apr 3, 2013 at 8:44 AM, Andrea Del Bene <an...@gmail.com>wrote:
> Hi,
>
> do you know the best way to get the base URL for our Wicket application?
> For example
>
> "http://www.mysite.com/**myapplication<http://www.mysite.com/myapplication>
> "
>
> I'm using the following code at the moment:
>
>
> protected CharSequence extractBaseUrl(Request request) {
> Url originalUrl = request.getOriginalUrl();
> CharSequence baseUrl = originalUrl.getProtocol() + "://" +
> originalUrl.getHost() +
> ":" + originalUrl.getPort() +
> request.getContextPath();
>
>
> return baseUrl;
> }
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<us...@wicket.apache.org>
> For additional commands, e-mail: users-help@wicket.apache.org
>
>