码迷,mamicode.com
首页 > 其他好文 > 详细

Response对象

时间:2019-10-15 20:50:02      阅读:102      评论:0      收藏:0      [点我收藏+]

标签:set   响应头   eth   throws   his   post   xtend   tput   public   

功能:

  设置响应消息:

    1.设置响应行:HTTP/1.1 200 OK

      设置状态码:setStstus(int sc)

    2.设置响应头:

      setHeader(String name,String value)

    3.设置响应体:

      1.获取输出流

        字符输出流:PrintWriter getWriter()

        字节输出流:ServletOutputStream getOutputStream()

      2.使用输出流,将数据输出到客户端浏览器

 1 @WebServlet("/servletest5")
 2 public class ServleTest5 extends HttpServlet {
 3     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 4         //设置响应状态码为302
 5         response.setStatus(302);
 6     }
 7 
 8     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 9         this.doPost(request,response);
10     }
11 }

 

Response对象

标签:set   响应头   eth   throws   his   post   xtend   tput   public   

原文地址:https://www.cnblogs.com/aikang525/p/11679984.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!