ServletResponse简介

Servlet API provides two important interfaces ServletResponse and HttpServletResponse to assist in sending response to client.

Servlet API提供了两个重要的接口ServletResponseHttpServletResponse来帮助将响应发送到客户端。

ServletResponse的一些重要方法 (Some Important Methods of ServletResponse)

MethodsDescription
PrintWriter getWriter()returns a PrintWriter object that can send character text to the client.
void setBufferSize(int size)Sets the preferred buffer size for the body of the response
void setContentLength(int len) Sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Content-Length header
void setContentType(String type)sets the content type of the response being sent to the client before sending the respond.
void setBufferSize(int size)sets the preferred buffer size for the body of the response.
boolean isCommitted()returns a boolean indicating if the response has been committed
void setLocale(Locale loc) sets the locale of the response, if the response has not been committed yet.
方法 描述
PrintWriter getWriter() 返回一个PrintWriter对象,该对象可以将字符文本发送到客户端。
void setBufferSize(int size) 设置响应主体的首选缓冲区大小
void setContentLength(int len) 设置响应中内容主体的长度在HTTP servlet中,此方法设置HTTP Content-Length标头
void setContentType(String type) 设置发送响应之前发送给客户端的响应的内容类型。
void setBufferSize(int size) 设置响应主体的首选缓冲区大小。
boolean isCommitted() 返回一个布尔值,指示响应是否已提交
setLocale(Locale loc)无效 设置响应的语言环境(如果尚未提交响应)。

HttpServletResponse接口 (HttpServletResponse Interface)

HttpServletResponse interface adds the methods that relates to the HTTP response.

HttpServletResponse接口添加了与HTTP响应相关的方法。

servlet response

HttpServletResponse的一些重要方法 (Some Important Methods of HttpServletResponse)

MethodsDescription
void addCookie(Cookie cookie)adds the specified cookie to the response.
void sendRedirect(String location)Sends a temporary redirect response to the client using the specified redirect location URL and clears the buffer
int getStatus()gets the current status code of this response
String getHeader(String name)gets the value of the response header with the given name.
void setHeader(String name, String value)sets a response header with the given name and value
void setStatus(int sc)sets the status code for this response
void sendError(int sc, String msg)sends an error response to the client using the specified status and clears the buffer
方法 描述
无效addCookie(Cookie cookie) 将指定的cookie添加到响应中。
void sendRedirect(String location) 使用指定的重定向位置URL向客户端发送临时重定向响应并清除缓冲区
int getStatus() 获取此响应的当前状态代码
字符串getHeader(String name) 获取具有给定名称的响应头的值。
void setHeader(String name, String value) 设置具有给定名称和值的响应头
无效setStatus(int sc) 设置此响应的状态码
void sendError(int sc, String msg) 使用指定的状态向客户端发送错误响应并清除缓冲区

翻译自: https://www.studytonight.com/servlet/servlet-response.php

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值