Response

Response

常见的响应头:

  1. Content-Type:服务器告诉客户端本次响应体数据格式以及编码格式
  2. Content-disposition:服务器告诉客户端以什么格式打开响应体数据
    • in-line:默认值,在当前页面内打开
    • attachment;filename=xxx:以附件形式打开响应体。文件下载

响应体

输出流

  • 字符输出流:PrintWriter getWriter()
  • 字节输出流:ServletOutputStream getOutputStream()

乱码问题:

  1. PrintWriter pw = reponse.getWriter() //获取的流的 默认编码ISO-8859-1
  2. 告诉浏览器相应体使用的编码(获取流之前设置!):response.setContentType("text/html; charset = utf-8")
posted @ 2022-04-10 17:39  Z_Y_L  阅读(31)  评论(0编辑  收藏  举报