HttpServletResponse interface to complete the function

Which of the following does not belong to HttpServletResponse interface to complete the function?

  • A:设置HTTP头标
  • B:设置cookie
  • C:读取路径信息
  • D:输出返回数据

Answer: C

A: Setup HTTP header  

1

response.setHeader("Refresh","3"); //三秒刷新页面一次

B: Set cookie

1

2

Cookie c1 = new Cookie("username","only");

response.addCookie(c1);

C (Error): read path information, request information read path

1

2

3

4

5

从request获取各种路径总结

request.getRealPath("url"); // 虚拟目录映射为实际目录

request.getRealPath("./");    // 网页所在的目录

request.getRealPath("../"); // 网页所在目录的上一层目录

request.getContextPath();    // 应用的web目录的名称

 

D: return data output

1

HttpServleteResponse.getOutputStream().write();



HttpServletResponse in the Servlet, when the server responds to a request of the client, necessary to use HttpServletResponse interface. Type of response may be used provided the setContentType () method. Transmitting character data to use the getWriter () returns an object. The table below is a common method of HttpServletResponse interfaces. Interface HttpServletResponse common methods described addCookie (Cookie cookie) specified Cookie added to the current response addHeader (String name, String value) of the specified name and value is added to the header of the response containsHeader (String name) Returns a Boolean value, it is determined whether a header of the response is provided encodeURL (String url) encoding the specified URL sendError (int sc) send an error to the client sendRedirect (String location) sending a provisional response to the client using the specified status code setDateHeader ( setStatus header names and values ​​set in response to a head setHeader (String name, String value) String name, long date) will be given names and dates will be set forth in response to (int sc) in response to the current setting state code setContentType (String ContentType) 

Guess you like

Origin blog.csdn.net/weixin_44018338/article/details/91458896