當前位置: 首頁>>代碼示例>>Java>>正文


Java UriUtils.encodePath方法代碼示例

本文整理匯總了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;
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-netflix,代碼行數:17,代碼來源:ProxyRequestHelper.java

示例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 "";
    }
}
 
開發者ID:af-not-found,項目名稱:blog-java2,代碼行數:10,代碼來源:MyFunction.java

示例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.");
		}
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:53,代碼來源:FormTag.java

示例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);
}
 
開發者ID:wq19880601,項目名稱:java-util-examples,代碼行數:10,代碼來源:EscapeUrl.java


注:本文中的org.springframework.web.util.UriUtils.encodePath方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。