java+request+date_Java HttpServletRequest.getDateHeader方法代碼示例

  • Post author:
  • Post category:java


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

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

示例1: checkIfModifiedSince

​點讚 3

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,

示例2: checkIfUnmodifiedSince

​點讚 3

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,

示例3: download

​點讚 3

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,

示例4: checkModifiedSince

​點讚 3

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類

public boolean checkModifiedSince(HttpServletRequest request, HttpServletResponse response, long lastMo



版权声明:本文为weixin_32972053原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。