本文整理匯總了Java中org.springframework.web.util.UriUtils.encodePath方法的典型用法代碼示例。如果您正苦於以下問題:Java UriUtils.encodePath方法的具體用法?Java UriUtils.encodePath怎麽用?Java UriUtils.encodePath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.web.util.UriUtils
的用法示例。
在下文中一共展示了UriUtils.encodePath方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: buildZuulRequestURI
import org.springframework.web.util.UriUtils; //導入方法依賴的package包/類
public String buildZuulRequestURI(HttpServletRequest request) {
RequestContext context = RequestContext.getCurrentContext();
String uri = request.getRequestURI();
String contextURI = (String) context.get(REQUEST_URI_KEY);
if (contextURI != null) {
try {
uri = UriUtils.encodePath(contextURI, characterEncoding(request));
}
catch (Exception e) {
log.debug(
"unable to encode uri path from context, falling back to uri from request",
e);
}
}
return uri;
}
示例2: urlEncodeUtf8
import org.springframework.web.util.UriUtils; //導入方法依賴的package包/類
public String urlEncodeUtf8(String str) {
try {
return UriUtils.encodePath(str, "UTF-8");
}
catch (UnsupportedEncodingException e) {
logger.error("urlEncodeUtf8 failed", e);
return "";
}
}
示例3: resolveAction
import org.springframework.web.util.UriUtils; //導入方法依賴的package包/類
/**
* Resolve the value of the '{@code action}' attribute.
* <p>If the user configured an '{@code action}' value then the result of
* evaluating this value is used. If the user configured an
* '{@code servletRelativeAction}' value then the value is prepended
* with the context and servlet paths, and the result is used. Otherwise, the
* {@link org.springframework.web.servlet.support.RequestContext#getRequestUri()
* originating URI} is used.
* @return the value that is to be used for the '{@code action}' attribute
*/
protected String resolveAction() throws JspException {
String action = getAction();
String servletRelativeAction = getServletRelativeAction();
if (StringUtils.hasText(action)) {
action = getDisplayString(evaluate(ACTION_ATTRIBUTE, action));
return processAction(action);
}
else if (StringUtils.hasText(servletRelativeAction)) {
String pathToServlet = getRequestContext().getPathToServlet();
if (servletRelativeAction.startsWith("/") &&
!servletRelativeAction.startsWith(getRequestContext().getContextPath())) {
servletRelativeAction = pathToServlet + servletRelativeAction;
}
servletRelativeAction = getDisplayString(evaluate(ACTION_ATTRIBUTE, servletRelativeAction));
return processAction(servletRelativeAction);
}
else {
String requestUri = getRequestContext().getRequestUri();
String encoding = this.pageContext.getResponse().getCharacterEncoding();
try {
requestUri = UriUtils.encodePath(requestUri, encoding);
}
catch (UnsupportedEncodingException ex) {
// shouldn't happen - if it does, proceed with requestUri as-is
}
ServletResponse response = this.pageContext.getResponse();
if (response instanceof HttpServletResponse) {
requestUri = ((HttpServletResponse) response).encodeURL(requestUri);
String queryString = getRequestContext().getQueryString();
if (StringUtils.hasText(queryString)) {
requestUri += "?" + HtmlUtils.htmlEscape(queryString);
}
}
if (StringUtils.hasText(requestUri)) {
return processAction(requestUri);
}
else {
throw new IllegalArgumentException("Attribute 'action' is required. " +
"Attempted to resolve against current request URI but request URI was null.");
}
}
}
示例4: escpae_url_with_spring
import org.springframework.web.util.UriUtils; //導入方法依賴的package包/類
@Test
public void escpae_url_with_spring () throws UnsupportedEncodingException {
// If you are using Java 7 you can use StandardCharsets OR use Guava Charsets
String urlEscaped = UriUtils.encodePath(URL_TO_ESCAPE, Charsets.UTF_8.toString());
assertEquals("http://www.leveluplunch.com%3Fsomevar=abc123&someothervar", urlEscaped);
}