1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
public static String urlFor(final Class<? extends WebPage> pageClass, final PageParameters params)
{
return WicketHelper.getContextUrl() + RequestCycle.get().urlFor(pageClass, params);
}
public static String getContextUrl()
{
WebRequest wr = (WebRequest) RequestCycle.get().getRequest();
HttpServletRequest req = wr.getHttpServletRequest();
StringBuffer url = HttpHelper.getContextUrl(req);
return url.toString();
}
public static StringBuffer getContextUrl(final HttpServletRequest req)
{
String protocol = req.isSecure() ? "https://" : "http://";
String hostname = req.getServerName();
int port = req.getServerPort();
StringBuffer url = new StringBuffer();
url.append(protocol);
url.append(hostname);
if ((port != 80) && (port != 443))
{
url.append(":");
url.append(port);
}
String ctx = req.getSession().getServletContext().getContextPath();
if (!ctx.startsWith("/"))
{
ctx = '/' + ctx;
}
if (!ctx.endsWith("/"))
{
ctx = ctx + '/';
}
url.append(ctx);
return url;
} |
Partager