response对响应的设置

Posted zhai1997

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了response对响应的设置相关的知识,希望对你有一定的参考价值。

1、response对象设置响应行状态码:

 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
    response.setStatus(404);
    

技术图片

 

 2、response对象添加响应头:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
Date date=new Date(121344444);
response.addHeader("zzz","I love JAVA.");
response.addIntHeader("myself",22);
response.addDateHeader("Time:",date.getTime());

技术图片

 

 3、response对象设置响应头:

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
    Date date=new Date(121344444);
    response.addHeader("zzz","I love JAVA.");
    response.addIntHeader("myself",22);
    response.addDateHeader("Time:",date.getTime());
    response.setIntHeader("myself",23);
    

技术图片

 

以上是关于response对响应的设置的主要内容,如果未能解决你的问题,请参考以下文章

request和response对象

HttpServletResponse

js怎么获取response响应的值

Servlet学习——通过response设置响应体及中文乱码问题

Java 之 Response 对象

响应 Response