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


Java HttpServletResponse.setDateHeader方法代碼示例

本文整理匯總了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;
}
 
開發者ID:cx118118,項目名稱:ssm-rbac,代碼行數:24,代碼來源:PublicController.java

示例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());
    }
}
 
開發者ID:okingjerryo,項目名稱:WeiMusicCommunity-server,代碼行數:32,代碼來源:WebController.java

示例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;
}
 
開發者ID:zhiqiang94,項目名稱:BasicsProject,代碼行數:22,代碼來源:CaptchaUtil.java

示例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);

    }
}
 
開發者ID:ehsaniara,項目名稱:SpringMvcLoginSecureExample,代碼行數:29,代碼來源:AuthenticationFilter.java

示例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);
		}
	}
}
 
開發者ID:ForJ-Latech,項目名稱:fwm,代碼行數:34,代碼來源:Webservice1_0BSController.java

示例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");
}
 
開發者ID:dragon-yuan,項目名稱:Ins_fb_pictureSpider_WEB,代碼行數:11,代碼來源:ServletUtils.java

示例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);
}
 
開發者ID:yacy,項目名稱:yacy_grid_mcp,代碼行數:36,代碼來源:FileHandler.java

示例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);
}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:23,代碼來源:HTMLManagerServlet.java

示例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");
}
 
開發者ID:wkeyuan,項目名稱:DWSurvey,代碼行數:11,代碼來源:ServletUtils.java

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

示例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");
}
 
開發者ID:funtl,項目名稱:framework,代碼行數:11,代碼來源:Servlets.java

示例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);
			}
		}
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:29,代碼來源:OutputResultListener.java

示例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);
}
 
開發者ID:devefx,項目名稱:validator-web,代碼行數:13,代碼來源:CachingHandler.java

示例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);
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:22,代碼來源:HTMLManagerServlet.java

示例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);
        }

    }
 
開發者ID:muhatzg,項目名稱:burstcoin,代碼行數:39,代碼來源:APITestServlet.java


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