当前位置: 首页>>代码示例>>Java>>正文


Java HttpServletRequest.getDateHeader方法代码示例

本文整理汇总了Java中javax.servlet.http.HttpServletRequest.getDateHeader方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServletRequest.getDateHeader方法的具体用法?Java HttpServletRequest.getDateHeader怎么用?Java HttpServletRequest.getDateHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.servlet.http.HttpServletRequest的用法示例。


在下文中一共展示了HttpServletRequest.getDateHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkIfModifiedSince

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
 * Check if the if-modified-since condition is satisfied.
 *
 * @param request The servlet request we are processing
 * @param response The servlet response we are creating
 * @param resourceInfo File object
 * @return boolean true if the resource meets the specified condition,
 * and false if the condition is not satisfied, in which case request 
 * processing is stopped
 */
private boolean checkIfModifiedSince(HttpServletRequest request,
                                     HttpServletResponse response,
                                     ResourceInfo resourceInfo)
    throws IOException {
    try {
        long headerValue = request.getDateHeader("If-Modified-Since");
        long lastModified = resourceInfo.date;
        if (headerValue != -1) {

            // If an If-None-Match header has been specified, if modified since
            // is ignored.
            if ((request.getHeader("If-None-Match") == null) 
                && (lastModified <= headerValue + 1000)) {
                // The entity has not been modified since the date
                // specified by the client. This is not an error case.
                response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
                return false;
            }
        }
    } catch(IllegalArgumentException illegalArgument) {
        return false;
    }
    return true;

}
 
开发者ID:c-rainstorm,项目名称:jerrydog,代码行数:36,代码来源:DefaultServlet.java

示例2: checkIfModifiedSince

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
 * Check if the if-modified-since condition is satisfied.
 *
 * @param request The servlet request we are processing
 * @param response The servlet response we are creating
 * @param resourceAttributes File object
 * @return boolean true if the resource meets the specified condition,
 * and false if the condition is not satisfied, in which case request
 * processing is stopped
 */
protected boolean checkIfModifiedSince(HttpServletRequest request,
        HttpServletResponse response,
        ResourceAttributes resourceAttributes) {
    try {
        long headerValue = request.getDateHeader("If-Modified-Since");
        long lastModified = resourceAttributes.getLastModified();
        if (headerValue != -1) {

            // If an If-None-Match header has been specified, if modified since
            // is ignored.
            if ((request.getHeader("If-None-Match") == null)
                && (lastModified < headerValue + 1000)) {
                // The entity has not been modified since the date
                // specified by the client. This is not an error case.
                response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
                response.setHeader("ETag", resourceAttributes.getETag());

                return false;
            }
        }
    } catch (IllegalArgumentException illegalArgument) {
        return true;
    }
    return true;

}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:37,代码来源:DefaultServlet.java

示例3: checkIfUnmodifiedSince

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
 * Check if the if-unmodified-since condition is satisfied.
 *
 * @param request The servlet request we are processing
 * @param response The servlet response we are creating
 * @param resourceAttributes File object
 * @return boolean true if the resource meets the specified condition,
 * and false if the condition is not satisfied, in which case request
 * processing is stopped
 */
protected boolean checkIfUnmodifiedSince(HttpServletRequest request,
                                       HttpServletResponse response,
                                       ResourceAttributes resourceAttributes)
    throws IOException {
    try {
        long lastModified = resourceAttributes.getLastModified();
        long headerValue = request.getDateHeader("If-Unmodified-Since");
        if (headerValue != -1) {
            if ( lastModified >= (headerValue + 1000)) {
                // The entity has not been modified since the date
                // specified by the client. This is not an error case.
                response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);
                return false;
            }
        }
    } catch(IllegalArgumentException illegalArgument) {
        return true;
    }
    return true;

}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:32,代码来源:DefaultServlet.java

示例4: download

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@RequestMapping(value = "/download")
public void download(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    org.airsonic.player.domain.User user = securityService.getCurrentUser(request);
    if (!user.isDownloadRole()) {
        error(request, response, ErrorCode.NOT_AUTHORIZED, user.getUsername() + " is not authorized to download files.");
        return;
    }

    long ifModifiedSince = request.getDateHeader("If-Modified-Since");
    long lastModified = downloadController.getLastModified(request);

    if (ifModifiedSince != -1 && lastModified != -1 && lastModified <= ifModifiedSince) {
        response.sendError(HttpServletResponse.SC_NOT_MODIFIED);
        return;
    }

    if (lastModified != -1) {
        response.setDateHeader("Last-Modified", lastModified);
    }

    downloadController.handleRequest(request, response);
}
 
开发者ID:airsonic,项目名称:airsonic,代码行数:24,代码来源:SubsonicRESTController.java

示例5: checkModifiedSince

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
public boolean checkModifiedSince(HttpServletRequest request, HttpServletResponse response, long lastModified)
{
	long modifiedSince = request.getDateHeader("IF-MODIFIED-SINCE"); //$NON-NLS-1$
	boolean hasBeenModified = true;
	if( modifiedSince > 0 )
	{
		hasBeenModified = modifiedSince < (lastModified - (lastModified % 1000));
	}

	response.setDateHeader("Last-Modified", lastModified); //$NON-NLS-1$

	if( !hasBeenModified )
	{
		response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
	}

	return hasBeenModified;
}
 
开发者ID:equella,项目名称:Equella,代码行数:19,代码来源:ContentStreamWriter.java

示例6: checkIfUnmodifiedSince

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
 * Check if the if-unmodified-since condition is satisfied.
 *
 * @param request The servlet request we are processing
 * @param response The servlet response we are creating
 * @param resourceInfo File object
 * @return boolean true if the resource meets the specified condition,
 * and false if the condition is not satisfied, in which case request
 * processing is stopped
 */
protected boolean checkIfUnmodifiedSince(HttpServletRequest request,
                                       HttpServletResponse response,
                                       ResourceAttributes resourceAttributes)
    throws IOException {
    try {
        long lastModified = resourceAttributes.getLastModified();
        long headerValue = request.getDateHeader("If-Unmodified-Since");
        if (headerValue != -1) {
            if ( lastModified >= (headerValue + 1000)) {
                // The entity has not been modified since the date
                // specified by the client. This is not an error case.
                response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);
                return false;
            }
        }
    } catch(IllegalArgumentException illegalArgument) {
        return true;
    }
    return true;

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:32,代码来源:DefaultServlet.java

示例7: checkIfUnmodifiedSince

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
 * Check if the if-unmodified-since condition is satisfied.
 *
 * @param request The servlet request we are processing
 * @param response The servlet response we are creating
 * @param resourceInfo File object
 * @return boolean true if the resource meets the specified condition,
 * and false if the condition is not satisfied, in which case request 
 * processing is stopped
 */
private boolean checkIfUnmodifiedSince(HttpServletRequest request,
                                       HttpServletResponse response,
                                       ResourceInfo resourceInfo)
    throws IOException {
    try {
        long lastModified = resourceInfo.date;
        long headerValue = request.getDateHeader("If-Unmodified-Since");
        if (headerValue != -1) {
            if ( lastModified > headerValue ) {
                // The entity has not been modified since the date
                // specified by the client. This is not an error case.
                response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);
                return false;
            }
        }
    } catch(IllegalArgumentException illegalArgument) {
        return false;
    }
    return true;

}
 
开发者ID:c-rainstorm,项目名称:jerrydog,代码行数:32,代码来源:DefaultServlet.java

示例8: checkIfModifiedSince

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
 * Check if the if-modified-since condition is satisfied.
 *
 * @param request
 *            The servlet request we are processing
 * @param response
 *            The servlet response we are creating
 * @param resourceAttributes
 *            File object
 * @return boolean true if the resource meets the specified condition, and
 *         false if the condition is not satisfied, in which case request
 *         processing is stopped
 */
protected boolean checkIfModifiedSince(HttpServletRequest request, HttpServletResponse response,
		ResourceAttributes resourceAttributes) {
	try {
		long headerValue = request.getDateHeader("If-Modified-Since");
		long lastModified = resourceAttributes.getLastModified();
		if (headerValue != -1) {

			// If an If-None-Match header has been specified, if modified
			// since
			// is ignored.
			if ((request.getHeader("If-None-Match") == null) && (lastModified < headerValue + 1000)) {
				// The entity has not been modified since the date
				// specified by the client. This is not an error case.
				response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
				response.setHeader("ETag", resourceAttributes.getETag());

				return false;
			}
		}
	} catch (IllegalArgumentException illegalArgument) {
		return true;
	}
	return true;

}
 
开发者ID:how2j,项目名称:lazycat,代码行数:39,代码来源:DefaultServlet.java

示例9: checkIfUnmodifiedSince

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
 * Check if the if-unmodified-since condition is satisfied.
 *
 * @param request
 *            The servlet request we are processing
 * @param response
 *            The servlet response we are creating
 * @param resourceAttributes
 *            File object
 * @return boolean true if the resource meets the specified condition, and
 *         false if the condition is not satisfied, in which case request
 *         processing is stopped
 */
protected boolean checkIfUnmodifiedSince(HttpServletRequest request, HttpServletResponse response,
		ResourceAttributes resourceAttributes) throws IOException {
	try {
		long lastModified = resourceAttributes.getLastModified();
		long headerValue = request.getDateHeader("If-Unmodified-Since");
		if (headerValue != -1) {
			if (lastModified >= (headerValue + 1000)) {
				// The entity has not been modified since the date
				// specified by the client. This is not an error case.
				response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);
				return false;
			}
		}
	} catch (IllegalArgumentException illegalArgument) {
		return true;
	}
	return true;

}
 
开发者ID:how2j,项目名称:lazycat,代码行数:33,代码来源:DefaultServlet.java

示例10: checkIfModifiedSince

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
 * 根据浏览器If-Modified-Since Header, 计算文件是否已被修改.
 * <p>
 * 如果无修改, checkIfModify返回false ,设置304 not modify status.
 *
 * @param lastModified 内容的最后修改时间.
 */
public static boolean checkIfModifiedSince(HttpServletRequest request, HttpServletResponse response, long lastModified) {
	long ifModifiedSince = request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE);
	if ((ifModifiedSince != -1) && (lastModified < ifModifiedSince + 1000)) {
		response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
		return false;
	}
	return true;
}
 
开发者ID:funtl,项目名称:framework,代码行数:16,代码来源:Servlets.java

示例11: checkIfModifiedSince

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
 * 根据浏览器If-Modified-Since Header, 计算文件是否已被修改.
 * 
 * 如果无修改, checkIfModify返回false ,设置304 not modify status.
 * 
 * @param request
 *            HttpServletRequest
 * @param response
 *            HttpServletResponse
 * @param lastModified
 *            内容的最后修改时间.
 * @return boolean
 */
public static boolean checkIfModifiedSince(HttpServletRequest request,
        HttpServletResponse response, long lastModified) {
    long ifModifiedSince = request.getDateHeader("If-Modified-Since");

    if ((ifModifiedSince != -1)
            && (lastModified < (ifModifiedSince + MILL_SECONDS))) {
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);

        return false;
    }

    return true;
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:27,代码来源:ServletUtils.java

示例12: checkIfModifiedSince

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
 * Check if the if-modified-since condition is satisfied.
 *
 * @param request The servlet request we are processing
 * @param response The servlet response we are creating
 * @param resourceInfo File object
 * @return boolean true if the resource meets the specified condition,
 * and false if the condition is not satisfied, in which case request
 * processing is stopped
 */
protected boolean checkIfModifiedSince(HttpServletRequest request,
                                     HttpServletResponse response,
                                     ResourceAttributes resourceAttributes)
    throws IOException {
    try {
        long headerValue = request.getDateHeader("If-Modified-Since");
        long lastModified = resourceAttributes.getLastModified();
        if (headerValue != -1) {

            // If an If-None-Match header has been specified, if modified since
            // is ignored.
            if ((request.getHeader("If-None-Match") == null)
                && (lastModified < headerValue + 1000)) {
                // The entity has not been modified since the date
                // specified by the client. This is not an error case.
                response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
                response.setHeader("ETag", resourceAttributes.getETag());

                return false;
            }
        }
    } catch (IllegalArgumentException illegalArgument) {
        return true;
    }
    return true;

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:38,代码来源:DefaultServlet.java

示例13: checkIfModifiedSince

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
 * 根据浏览器If-Modified-Since Header, 计算文件是否已被修改.
 *
 * 如果无修改, checkIfModify返回false ,设置304 not modify status.
 *
 * @param lastModified 内容的最后修改时间.
 */
public static boolean checkIfModifiedSince(HttpServletRequest request, HttpServletResponse response,
                                           long lastModified) {
    long ifModifiedSince = request.getDateHeader("If-Modified-Since");
    if ((ifModifiedSince != -1) && (lastModified < ifModifiedSince + 1000)) {
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return false;
    }
    return true;
}
 
开发者ID:dragon-yuan,项目名称:Ins_fb_pictureSpider_WEB,代码行数:17,代码来源:ServletUtils.java

示例14: checkIfModifiedSince

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
 * 根据浏览器If-Modified-Since Header, 计算文件是否已被修改.
 * 
 * 如果无修改, checkIfModify返回false ,设置304 not modify status.
 * 
 * @param lastModified 内容的最后修改时间.
 */
public static boolean checkIfModifiedSince(HttpServletRequest request, HttpServletResponse response,
                                              long lastModified) {
	long ifModifiedSince = request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE);
	if ((ifModifiedSince != -1) && (lastModified < ifModifiedSince + 1000)) {
		response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
		return false;
	}
	return true;
}
 
开发者ID:egojit8,项目名称:easyweb,代码行数:17,代码来源:Servlets.java

示例15: notModified

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
 * Compares the "If-Modified-Since" header in this request (ir present) to
 * the last build date (if known) in order to determine whether the requested
 * data has been modified since the prior request.
 *
 * @param req the request
 * @return {@code true} iff we're sure that request is for a resource that
 *         has not been modified since the prior request
 */
public static boolean notModified(HttpServletRequest req) {
  long ifModDate = req.getDateHeader("If-Modified-Since");
  if (BuildData.getTimestamp() > 0 && ifModDate > 0) {
    if (ifModDate >= BuildData.getTimestamp()) {
      return true;
    }
  }
  return false;
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:19,代码来源:ModifiedHeaders.java


注:本文中的javax.servlet.http.HttpServletRequest.getDateHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。