Wicket: get URL from browser

I need to get the URL from the current web page opened in Firefox using Wicket. Can someone tell me how to do this?

+6
java wicket
source share
5 answers

You need to request the base HTTPServletRequest :

public class DummyPage extends WebPage{ private String getRequestUrl(){ // this is a wicket-specific request interface final Request request = getRequest(); if(request instanceof WebRequest){ final WebRequest wr = (WebRequest) request; // but this is the real thing final HttpServletRequest hsr = wr.getHttpServletRequest(); String reqUrl = hsr.getRequestURL().toString(); final String queryString = hsr.getQueryString(); if(queryString != null){ reqUrl += "?" + queryString; } return reqUrl; } return null; } } 

Reference:

+6
source share

Sean Patrick Floyd's decision seems obsolete for wicket 1.5

If using a wicket 1.5 (or higher, I think), here is the solution:

 RequestCycle.get().getUrlRenderer().renderFullUrl( Url.parse(urlFor(MyPage.class,null).toString())); 

Link

Getting the URL to display

+5
source share

To get the current page URL, use webrequest and UrlRenderer:

 Url url = ((WebRequest)RequestCycle.get().getRequest()).getUrl(); String fullUrl = RequestCycle.get().getUrlRenderer().renderFullUrl(url); 
+5
source share

Depending on what exactly you want, this may not be possible. There is a short guide here in Wicket Wicket , but there are some caveats in it, in particular that it only returns relative URLs in versions of Wicket after 1.3. However, the method used

 String url = urlFor("pageMapName", MyPage.class, new PageParameters("foo=bar")); 

If you switch to an alternative wiki method - one that is associated with a form - be warned: getPage() not part of the public Wicket API .

+1
source share

It works. I am using wicket 1.5;

new URL (RequestCycle.get (). getUrlRenderer (). renderFullUrl (Url.parse (urlFor (HomePage.class, null) .ToString ()))) getAuthority ();.

Example: http://example.com:80/a_long_path/

getAuthproty () will return example.com:80

getHost () will return example.com.

+1
source share

All Articles