当前位置: 首页>>代码示例>>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;未经允许,请勿转载。