本文整理匯總了Java中javax.servlet.http.HttpServletResponse.setDateHeader方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpServletResponse.setDateHeader方法的具體用法?Java HttpServletResponse.setDateHeader怎麽用?Java HttpServletResponse.setDateHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.servlet.http.HttpServletResponse
的用法示例。
在下文中一共展示了HttpServletResponse.setDateHeader方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: verify
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
* 生成驗證碼的邏輯
*/
@RequestMapping("verify")
private ModelAndView verify(HttpServletRequest request, HttpServletResponse response) throws Exception {
HttpSession session = request.getSession();
response.setDateHeader("Expires", 0);
response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
response.addHeader("Cache-Control", "post-check=0, pre-check=0");
response.setHeader("Pragma", "no-cache");
response.setContentType("image/jpeg");
String capText = captchaProducer.createText();
session.setAttribute(Constants.KAPTCHA_SESSION_KEY, capText);
BufferedImage bi = captchaProducer.createImage(capText);
ServletOutputStream out = response.getOutputStream();
ImageIO.write(bi, "jpg", out);
try {
out.flush();
} finally {
out.close();
}
return null;
}
示例2: countGoodsNumByCategoryId
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@RequestMapping("/webloginAJ")
public void countGoodsNumByCategoryId(HttpServletRequest request, HttpServletResponse response) {
response.setContentType("text/piain;charset=Utf-8");
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
HttpJson json = new HttpJson();
json.setStatusCode(400);
json.setMessage("testMessage");
json.constractJsonString();
try {
PrintWriter out = response.getWriter();
String jsonpCallback = request.getParameter("jsonpCallback");// 客戶端請求
JSONObject object = new JSONObject();
List<Login> send = new ArrayList<>();
for (Integer i = 0; i < 3; i++) {
Login thisl = new Login();
thisl.setUAName(i.toString() + "啦啦啦啦");
send.add(thisl);
}
object.put("list", send);
out.println(jsonpCallback + "(" + object.toString() + ")");// 返回jsonp格式數據
out.flush();
out.close();
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
示例3: getJPGCode
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**獲取JPG格式動畫驗證碼*/
public CaptchaCreateUtil getJPGCode(HttpServletResponse response){
try {
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("image/jpg");
/**
* jgp格式驗證碼
* 寬,高,位數。
*/
Captcha captcha = new SpecCaptcha(width,height,size);
//輸出
captcha.out(response.getOutputStream());
storageUtil.storageInfo(storageUtil.getLoginMemberId(), Statics.CAPTCHA_CODE_KEY+"_"+id, captcha.text());
storageUtil.storageInfo(storageUtil.getLoginMemberId(), Statics.CAPTCHA_CODE_KEY+"_"+id+"_time", System.currentTimeMillis());
} catch (Exception e) {
System.out.println("獲取驗證碼異常:"+e.getMessage());
}
return this;
}
示例4: doFilter
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
CustomerBean customerBean =
(CustomerBean) ((HttpServletRequest) req).getSession().getAttribute("customerBean");
String path = ((HttpServletRequest) req).getRequestURI();
if (!path.contains("javax.faces.resource")) {
if (customerBean != null && customerBean.isLogin()) {
chain.doFilter(req, resp); // Just continue chain.
} else {
HttpServletResponse response = (HttpServletResponse) resp;
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
response.setDateHeader("Expires", 0); // Proxies.
//if not login
if (path.contains("/index.xhtml")) {
//Kill The Browser cache
System.out.println("Should Be Redirected");
req.getRequestDispatcher("/logout.xhtml?faces-redirect=true").forward(req, resp);
} else {
chain.doFilter(req, resp);
}
}
} else {
chain.doFilter(req, resp);
}
}
示例5: getImage
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@RequestMapping(value = "/webservice1_0bs/multimediaImage/{imageFile}.{ender}", method = RequestMethod.GET)
@ResponseBody
public void getImage(@PathVariable("imageFile") String imageFile, @PathVariable("ender") String end,
HttpServletResponse response) {
try {
ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream();
File img = App.worldFileUtil.findMultimedia(imageFile + "." + end);
log.debug(img.getAbsolutePath());
log.debug(img.exists());
BufferedImage image = ImageIO.read(img);
ImageIO.write(image, end, jpegOutputStream);
byte[] imgByte = jpegOutputStream.toByteArray();
response.setHeader("Cache-Control", "no-store");
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("image/" + end);
ServletOutputStream responseOutputStream = response.getOutputStream();
responseOutputStream.write(imgByte);
responseOutputStream.flush();
responseOutputStream.close();
} catch (IOException e1) {
log.error(e1);
try {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
} catch (Exception e) {
log.error(e);
}
}
}
示例6: setDisableCacheHeader
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
* 設置禁止客戶端緩存的Header.
*/
public static void setDisableCacheHeader(HttpServletResponse response) {
//Http 1.0 header
response.setDateHeader("Expires", 1L);
response.addHeader("Pragma", "no-cache");
//Http 1.1 header
response.setHeader("Cache-Control", "no-cache, no-store, max-age=0");
}
示例7: setCaching
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
public static void setCaching(final HttpServletResponse response, final int expiresSeconds) {
if (response instanceof org.eclipse.jetty.server.Response) {
org.eclipse.jetty.server.Response r = (org.eclipse.jetty.server.Response) response;
HttpFields fields = r.getHttpFields();
// remove the last-modified field since caching otherwise does not work
/*
https://www.ietf.org/rfc/rfc2616.txt
"if the response does have a Last-Modified time, the heuristic
expiration value SHOULD be no more than some fraction of the interval
since that time. A typical setting of this fraction might be 10%."
*/
fields.remove(HttpHeader.LAST_MODIFIED); // if this field is present, the reload-time is a 10% fraction of ttl and other caching headers do not work
// cache-control: allow shared caching (i.e. proxies) and set expires age for cache
if(expiresSeconds == 0){
fields.put(HttpHeader.CACHE_CONTROL, "public, no-store, max-age=" + Integer.toString(expiresSeconds)); // seconds
}
else {
fields.put(HttpHeader.CACHE_CONTROL, "public, max-age=" + Integer.toString(expiresSeconds)); // seconds
}
} else {
response.setHeader(HttpHeader.LAST_MODIFIED.asString(), ""); // not really the best wqy to remove this header but there is no other option
if(expiresSeconds == 0){
response.setHeader(HttpHeader.CACHE_CONTROL.asString(), "public, no-store, max-age=" + Integer.toString(expiresSeconds));
}
else{
response.setHeader(HttpHeader.CACHE_CONTROL.asString(), "public, max-age=" + Integer.toString(expiresSeconds));
}
}
// expires: define how long the file shall stay in a cache if cache-control is not used for this information
response.setDateHeader(HttpHeader.EXPIRES.asString(), System.currentTimeMillis() + expiresSeconds * 1000);
}
示例8: displaySessionDetailPage
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
*
* @param req
* @param resp
* @param smClient
* StringManager for the client's locale
* @throws ServletException
* @throws IOException
*/
protected void displaySessionDetailPage(HttpServletRequest req, HttpServletResponse resp, ContextName cn,
String sessionId, StringManager smClient) throws ServletException, IOException {
Session session = getSessionForNameAndId(cn, sessionId, smClient);
// strong>NOTE</strong> - This header will be overridden
// automatically if a <code>RequestDispatcher.forward()</code> call is
// ultimately invoked.
resp.setHeader("Pragma", "No-cache"); // HTTP 1.0
resp.setHeader("Cache-Control", "no-cache,no-store,max-age=0"); // HTTP
// 1.1
resp.setDateHeader("Expires", 0); // 0 means now
req.setAttribute("currentSession", session);
getServletContext().getRequestDispatcher(resp.encodeURL(sessionDetailJspPath)).include(req, resp);
}
示例9: setDisableCacheHeader
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
* 設置禁止客戶端緩存的Header.
*/
public static void setDisableCacheHeader(HttpServletResponse response) {
//Http 1.0 header
response.setDateHeader("Expires", 1L);
response.addHeader("Pragma", "no-cache");
//Http 1.1 header
response.setHeader("Cache-Control", "no-cache, no-store, max-age=0");
}
示例10: setExpiresHeader
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
* 設置客戶端緩存過期時間 的Header.
*/
public static void setExpiresHeader(HttpServletResponse response, long expiresSeconds) {
// Http 1.0 header, set a fix expires date.
response.setDateHeader(HttpHeaders.EXPIRES, System.currentTimeMillis() + expiresSeconds * 1000);
// Http 1.1 header, set a time after now.
response.setHeader(HttpHeaders.CACHE_CONTROL, "private, max-age=" + expiresSeconds);
}
示例11: setNoCacheHeader
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
* 設置禁止客戶端緩存的Header.
*/
public static void setNoCacheHeader(HttpServletResponse response) {
// Http 1.0 header
response.setDateHeader(HttpHeaders.EXPIRES, 1L);
response.addHeader(HttpHeaders.PRAGMA, "no-cache");
// Http 1.1 header
response.setHeader(HttpHeaders.CACHE_CONTROL, "no-cache, no-store, max-age=0");
}
示例12: returnResult
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@Override
@SuppressWarnings("nls")
public void returnResult(SectionResult result, String fromId)
{
if( result != null )
{
HttpServletResponse response = info.getResponse();
info.setRendered();
if( result instanceof SectionRenderable )
{
response.setContentType("text/html");
response.setHeader("Cache-Control", "no-cache, no-store");
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", 0);
response.setCharacterEncoding("UTF-8");
SectionRenderable renderable = (SectionRenderable) result;
try( SectionWriter writer = new SectionWriter(response.getWriter(), info) )
{
writer.render(renderable);
}
catch( IOException e )
{
SectionUtils.throwRuntime(e);
}
}
}
}
示例13: addNoCacheHeaders
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
* Add headers to prevent browsers and proxies from caching this reply.
* @param response The response to add headers to
*/
protected void addNoCacheHeaders(HttpServletResponse response) {
// Set standard HTTP/1.1 no-cache headers.
response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
// Set standard HTTP/1.0 no-cache header.
response.setHeader("Pragma", "no-cache");
// Set to expire far in the past. Prevents caching at the proxy server
response.setDateHeader("Expires", 0);
}
示例14: displaySessionDetailPage
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
*
* @param req
* @param resp
* @param smClient StringManager for the client's locale
* @throws ServletException
* @throws IOException
*/
protected void displaySessionDetailPage(HttpServletRequest req,
HttpServletResponse resp, ContextName cn, String sessionId,
StringManager smClient) throws ServletException, IOException {
Session session = getSessionForNameAndId(cn, sessionId, smClient);
//strong>NOTE</strong> - This header will be overridden
// automatically if a <code>RequestDispatcher.forward()</code> call is
// ultimately invoked.
resp.setHeader("Pragma", "No-cache"); // HTTP 1.0
resp.setHeader("Cache-Control", "no-cache,no-store,max-age=0"); // HTTP 1.1
resp.setDateHeader("Expires", 0); // 0 means now
req.setAttribute("currentSession", session);
getServletContext().getRequestDispatcher(resp.encodeURL(sessionDetailJspPath)).include(req, resp);
}
示例15: doGet
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setHeader("Cache-Control", "no-cache, no-store, must-revalidate, private");
resp.setHeader("Pragma", "no-cache");
resp.setDateHeader("Expires", 0);
resp.setContentType("text/html; charset=UTF-8");
if (API.allowedBotHosts != null && ! API.allowedBotHosts.contains(req.getRemoteHost())) {
resp.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
try (PrintWriter writer = resp.getWriter()) {
writer.print(header1);
writer.print(buildLinks(req));
writer.print(header2);
String requestType = Convert.nullToEmpty(req.getParameter("requestType"));
APIServlet.APIRequestHandler requestHandler = APIServlet.apiRequestHandlers.get(requestType);
StringBuilder bufJSCalls = new StringBuilder();
if (requestHandler != null) {
writer.print(form(requestType, true, requestHandler.getClass().getName(), requestHandler.getParameters(), requestHandler.requirePost()));
bufJSCalls.append("apiCalls.push(\"").append(requestType).append("\");\n");
} else {
String requestTag = Convert.nullToEmpty(req.getParameter("requestTag"));
Set<String> taggedTypes = requestTags.get(requestTag);
for (String type : (taggedTypes != null ? taggedTypes : allRequestTypes)) {
requestHandler = APIServlet.apiRequestHandlers.get(type);
writer.print(form(type, false, requestHandler.getClass().getName(), APIServlet.apiRequestHandlers.get(type).getParameters(),
APIServlet.apiRequestHandlers.get(type).requirePost()));
bufJSCalls.append("apiCalls.push(\"").append(type).append("\");\n");
}
}
writer.print(footer1);
writer.print(bufJSCalls.toString());
writer.print(footer2);
}
}