zoukankan      html  css  js  c++  java
  • servlet响应-头部信息的设置

    servlet响应

    头部信息的设置

    //添加头部信息
    
        resp.addHeader("名字","值");
        //添加该名字与值
        boolean falg = resp.containsHeader("名字");
        //查询响应头中是否包含某个名字,存在返回true,否则返回 false
    
    
    //添加响应头时,名字可以随便取,但是一般使用常见的名字
    
        //Server -> tomcat版本
    
        //Date -> 时间
            resp.setDateHeader("Date",long-时间的毫秒数);
            //与resp.addHeader("Date","值")效果相同
    
        //Content-Type -> 响应返回的内容类型 
            resp.setContentType("text/html;charset=utf-8");
            //与resp.addHeader("Content-Type","text/html;charset=utf-8")效果相同
    
        //Location -> 302时,返回请求资源的新路径
    
        //Content-Encoding -> 服务端能够发送压缩编码类型
             resp.addHeader("Content-Encoding","gzip");
    
        //Content-Length -> 服务器发送的压缩数据的长度
            resp.addHeader("Content-Length","长度");
    
        //Content-language -> 服务器发送的语言类型
            resp.addHeader("Content-Language","zh-cn");
    
        //Last-Modified -> 服务端对该资源最后的修改时间
            resp.addHeader("Last-Modifies",new Date().toString());
    
        //Content-Disposition -> 服务器要求客户端以下载文件的方式打开该文件
            resp.addHeader("Content-Disposition","attachment;filename=下载文件名.后缀名")
    
        //设置浏览器是否缓存
            resp.addHeader("Expires","-1");
            resp.addHeader("Cache-Control","no-cache");
            resp.addHeader("Pragma","no-cache");
            //针对不同浏览器的兼容

     

  • 相关阅读:
    Java中的集合Queue
    CountDownTimer
    CountDownTimer
    CountDownTimer
    CountDownTimer
    【10月新版】Aspose.Pdf 10月新版V17.10发布 | 附下载
    【10月新版】Aspose.Pdf 10月新版V17.10发布 | 附下载
    【10月新版】Aspose.Pdf 10月新版V17.10发布 | 附下载
    【10月新版】Aspose.Pdf 10月新版V17.10发布 | 附下载
    什么是区块链 Layer 0 扩容
  • 原文地址:https://www.cnblogs.com/-Archenemy-/p/12664031.html
Copyright © 2011-2022 走看看