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


Java HttpServletRequest.getPathTranslated方法代碼示例

本文整理匯總了Java中javax.servlet.http.HttpServletRequest.getPathTranslated方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpServletRequest.getPathTranslated方法的具體用法?Java HttpServletRequest.getPathTranslated怎麽用?Java HttpServletRequest.getPathTranslated使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.servlet.http.HttpServletRequest的用法示例。


在下文中一共展示了HttpServletRequest.getPathTranslated方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doFilter

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
public void doFilter(ServletRequest request, ServletResponse response,
        FilterChain chain) throws IOException, ServletException {

    if (!(request instanceof HttpServletRequest) || !(response instanceof HttpServletResponse)) {
        throw new ServletException("Just supports HTTP requests");
    }
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpServletResponse httpResponse = (HttpServletResponse) response;

    int cacheTime = 0;

    for(Pattern pattern : TIME_FOR_URL.keySet()) {
        if(pattern.matcher(httpRequest.getRequestURI()).matches()) {
            cacheTime = TIME_FOR_URL.get(pattern);
        }
    }
    httpResponse.setHeader(HttpHeaders.CACHE_CONTROL, "max-age="+cacheTime+", must-revalidate");

    httpRequest.getRequestURI();

    String key = httpRequest.getPathTranslated();
    if(cache.containsKey(key)) {
        String expectedEtag = httpRequest.getHeader(HttpHeaders.IF_NONE_MATCH);
        String currentEtag = cache.get(key);
        if(expectedEtag != null && expectedEtag.equals(currentEtag)) {
            httpResponse.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
            return;
        }
    }

    filter.doFilter(request, response, chain);
    String etag = httpResponse.getHeader(HttpHeaders.ETAG);
    cache.put(key, etag);
}
 
開發者ID:BBVA,項目名稱:mirrorgate,代碼行數:36,代碼來源:OneTimeETagGenerationFilter.java

示例2: InvokerHttpRequest

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
 * Construct a new wrapped request around the specified servlet request.
 *
 * @param request The servlet request being wrapped
 */
public InvokerHttpRequest(HttpServletRequest request) {

    super(request);
    this.pathInfo = request.getPathInfo();
    this.pathTranslated = request.getPathTranslated();
    this.requestURI = request.getRequestURI();
    this.servletPath = request.getServletPath();

}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:15,代碼來源:InvokerHttpRequest.java

示例3: ServletRequestCopy

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
public ServletRequestCopy(HttpServletRequest request) {
	this.servletPath = request.getServletPath();
	this.contextPath = request.getContextPath();
	this.pathInfo = request.getPathInfo();
	this.requestUri = request.getRequestURI();
	this.requestURL = request.getRequestURL();
	this.method = request.getMethod();
	this.serverName = request.getServerName();
	this.serverPort = request.getServerPort();
	this.protocol = request.getProtocol();
	this.scheme = request.getScheme();
	
	
	/*
	 * have to comment out below two lines as otherwise web socket will
	 * report UnSupportedOperationException upon connection
	 */
	//this.characterEncoding = request.getCharacterEncoding();
	//this.contentType = request.getContentType();
	//this.requestedSessionId = request.getRequestedSessionId();
	this.characterEncoding = null;
	this.contentType = null;
	this.requestedSessionId = null;
	
	this.locale = request.getLocale();
	this.locales = request.getLocales();
	this.isSecure = request.isSecure();
	this.remoteUser = request.getRemoteUser();
	this.remoteAddr = request.getRemoteAddr();
	this.remoteHost = request.getRemoteHost();
	this.remotePort = request.getRemotePort();
	this.localAddr = request.getLocalAddr();
	this.localName = request.getLocalName();
	this.localPort = request.getLocalPort();
	this.pathTranslated = request.getPathTranslated();
	this.principal = request.getUserPrincipal();

	HttpSession session = request.getSession(true);
	httpSession = new HttpSessionCopy(session);

	String s;
	Enumeration<String> e = request.getHeaderNames();
	while (e != null && e.hasMoreElements()) {
		s = e.nextElement();
		Enumeration<String> headerValues = request.getHeaders(s);
		this.headers.put(s, headerValues);
	}

	e = request.getAttributeNames();
	while (e != null && e.hasMoreElements()) {
		s = e.nextElement();
		attributes.put(s, request.getAttribute(s));
	}

	e = request.getParameterNames();
	while (e != null && e.hasMoreElements()) {
		s = e.nextElement();
		parameters.put(s, request.getParameterValues(s));
	}
}
 
開發者ID:jmfgdev,項目名稱:gitplex-mit,代碼行數:61,代碼來源:ServletRequestCopy.java


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