本文整理了Java中org.apache.wicket.request.Request.getClientUrl
方法的一些代码示例,展示了Request.getClientUrl
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.getClientUrl
方法的具体详情如下:
包路径:org.apache.wicket.request.Request
类名称:Request
方法名:getClientUrl
[英]Returns the url against which the client, usually the browser, will resolve relative urls in the rendered markup. If the client is a browser this is the url in the browser's address bar.
Under normal circumstances the client and request ( #getUrl()) urls are the same. Handling an Ajax request, however, is a good example of when they may be different. Technologies such as XHR are free to request whatever url they wish without modifying the client url; however, any produced urls will be evaluated by the client against the client url - not against the request url.
Lets take a simple example:
Suppose we are on a client detail page. This page contains an Ajax link which opens a list of client's orders. Each order has a link that goes to the order detail page. The client detail page is located at
/detail/customer/15
and the order detail page is located at
/order/22
The Ajax link which renders the detail section is located at
/detail/wicket?page 3
Lets run through the execution and see what happens when the XHR request is processed:
request 1: /details/customer/15
client url: details/customer/15 (the url in the browser's address bar)
request url: details/customer/15
Wicket renders relative Ajax details anchor as ../../wicket/page?3
../../wicket/page?3 resolved against current client url details/customer/15 yields:
request 2: /wicket/page?3
client url: customer/15 (unchanged since XHRs requests dont change it)
request url: wicket/ajax/page?3
now Wicket has to render a relative url to /details/order/22. If Wicket renders
it against the request url it will be: ../order/22, and later evaluated on the
client will result in /customer/order/22 which is incorrect.
This is why implementations of Request must track the client url, so that relative urls can be rendered against the same url they will be evaluated against on the client - which is not always the same as the request url. For example, Wicket's Ajax implementation always sends the current client url in a header along with the XHR request so that Wicket can correctly render relative urls against it.
[中]返回客户端(通常是浏览器)将根据其解析呈现标记中的相对url的url。如果客户端是浏览器,这是浏览器地址栏中的url。
在正常情况下,客户端和请求(#getUrl())URL是相同的。然而,处理Ajax请求是一个很好的例子,可以说明它们何时可能不同。XHR等技术可以在不修改客户端url的情况下自由请求任何url;但是,任何生成的url都将由客户端根据客户端url进行评估,而不是根据请求url进行评估。
让我们举一个简单的例子:
假设我们在客户详细信息页面上。此页面包含一个Ajax链接,用于打开客户订单列表。每个订单都有一个指向订单详细信息页面的链接。客户详细信息页面位于
/detail/customer/15
订单详细信息页面位于
/order/22
呈现详细信息部分的Ajax链接位于
/detail/wicket?page 3
让我们运行整个执行过程,看看处理XHR请求时会发生什么:
request 1: /details/customer/15
client url: details/customer/15 (the url in the browser's address bar)
request url: details/customer/15
Wicket renders relative Ajax details anchor as ../../wicket/page?3
../../wicket/page?3 resolved against current client url details/customer/15 yields:
request 2: /wicket/page?3
client url: customer/15 (unchanged since XHRs requests dont change it)
request url: wicket/ajax/page?3
now Wicket has to render a relative url to /details/order/22. If Wicket renders
it against the request url it will be: ../order/22, and later evaluated on the
client will result in /customer/order/22 which is incorrect.
这就是为什么请求的实现必须跟踪客户端url,因此,相对url可以根据在客户端上对其进行评估的同一url呈现——这并不总是与请求url相同。例如,Wicket的Ajax实现总是将当前客户端url与XHR请求一起发送到报头中,这样Wicket就可以正确地呈现针对它的相对url。
代码示例来源:origin: org.apache.wicket/wicket-request
/**
* Construct.
*
* @param request
* Request that serves as the base for rendering urls
*/
public UrlRenderer(final Request request)
{
this.request = request;
baseUrl = request.getClientUrl();
}
代码示例来源:origin: apache/wicket
@Override
public Url getClientUrl()
{
return Request.this.getClientUrl();
}
代码示例来源:origin: org.apache.wicket/wicket-request
@Override
public Url getClientUrl()
{
return Request.this.getClientUrl();
}
代码示例来源:origin: apache/wicket
/**
* Construct.
*
* @param request
* Request that serves as the base for rendering urls
*/
public UrlRenderer(final Request request)
{
this.request = request;
baseUrl = request.getClientUrl();
}
代码示例来源:origin: apache/wicket
/**
* Gets the protocol that should be used to render the url
*
* @param url
* url being rendered
* @return the protocol or {@code null} if none is set
*/
protected String resolveProtocol(final Url url)
{
return choose(url.getProtocol(), baseUrl.getProtocol(), request.getClientUrl()
.getProtocol());
}
代码示例来源:origin: org.apache.wicket/wicket-request
/**
* Gets port that should be used to render the url
*
* @param url
* url being rendered
* @return port or {@code null} if none is set
*/
protected Integer resolvePort(final Url url)
{
return choose(url.getPort(), baseUrl.getPort(), request.getClientUrl().getPort());
}
代码示例来源:origin: apache/wicket
/**
* Gets port that should be used to render the url
*
* @param url
* url being rendered
* @return port or {@code null} if none is set
*/
protected Integer resolvePort(final Url url)
{
return choose(url.getPort(), baseUrl.getPort(), request.getClientUrl().getPort());
}
代码示例来源:origin: apache/wicket
/**
* Gets the host name that should be used to render the url
*
* @param url
* url being rendered
* @return the host name or {@code null} if none is set
*/
protected String resolveHost(final Url url)
{
return choose(url.getHost(), baseUrl.getHost(), request.getClientUrl().getHost());
}
代码示例来源:origin: org.apache.wicket/wicket-request
/**
* Gets the host name that should be used to render the url
*
* @param url
* url being rendered
* @return the host name or {@code null} if none is set
*/
protected String resolveHost(final Url url)
{
return choose(url.getHost(), baseUrl.getHost(), request.getClientUrl().getHost());
}
代码示例来源:origin: org.apache.wicket/wicket-request
/**
* Gets the protocol that should be used to render the url
*
* @param url
* url being rendered
* @return the protocol or {@code null} if none is set
*/
protected String resolveProtocol(final Url url)
{
return choose(url.getProtocol(), baseUrl.getProtocol(), request.getClientUrl()
.getProtocol());
}
代码示例来源:origin: apache/wicket
/**
* Determines whether a URL should be rendered in its full form
*
* @param url
* @return {@code true} if URL should be rendered in the full form
*/
protected boolean shouldRenderAsFull(final Url url)
{
Url clientUrl = request.getClientUrl();
if (!Strings.isEmpty(url.getProtocol()) &&
!url.getProtocol().equals(clientUrl.getProtocol()))
{
return true;
}
if (!Strings.isEmpty(url.getHost()) && !url.getHost().equals(clientUrl.getHost()))
{
return true;
}
if ((url.getPort() != null) && !url.getPort().equals(clientUrl.getPort()))
{
return true;
}
if (url.isContextAbsolute())
{
// do not relativize urls like "/a/b"
return true;
}
return false;
}
代码示例来源:origin: org.apache.wicket/wicket-request
/**
* Determines whether a URL should be rendered in its full form
*
* @param url
* @return {@code true} if URL should be rendered in the full form
*/
protected boolean shouldRenderAsFull(final Url url)
{
Url clientUrl = request.getClientUrl();
if (!Strings.isEmpty(url.getProtocol()) &&
!url.getProtocol().equals(clientUrl.getProtocol()))
{
return true;
}
if (!Strings.isEmpty(url.getHost()) && !url.getHost().equals(clientUrl.getHost()))
{
return true;
}
if ((url.getPort() != null) && !url.getPort().equals(clientUrl.getPort()))
{
return true;
}
if (url.isContextAbsolute())
{
// do not relativize urls like "/a/b"
return true;
}
return false;
}
代码示例来源:origin: org.geoserver.web/gs-web-wms
if (StringUtils.isEmpty(proxyBaseUrl)) {
Request r = getRequest();
Url clientUrl = r.getClientUrl();
styleUrl =
clientUrl.getProtocol()
代码示例来源:origin: apache/wicket
Url baseUrl = request.getClientUrl();
String namespace = getContext().getNamespace();
String bookmarkableIdentifier = getContext().getBookmarkableIdentifier();
代码示例来源:origin: org.apache.wicket/wicket-core
Url baseUrl = request.getClientUrl();
String namespace = getContext().getNamespace();
String bookmarkableIdentifier = getContext().getBookmarkableIdentifier();
代码示例来源:origin: org.wicketstuff/wicketstuff-portlet
Url clientUrl = request.getClientUrl();
if (!shouldRedirectToExternalUrl(absoluteUrl, clientUrl)) {
if (absoluteUrl.getProtocol() != null) {
代码示例来源:origin: apache/wicket
Url baseUrl = request.getClientUrl();
String namespace = getContext().getNamespace();
String pageIdentifier = getContext().getPageIdentifier();
代码示例来源:origin: org.apache.wicket/wicket-core
Url baseUrl = request.getClientUrl();
String namespace = getContext().getNamespace();
String pageIdentifier = getContext().getPageIdentifier();
内容来源于网络,如有侵权,请联系作者删除!