HttpServletResponse 获取返回结果
时间: 2023-08-11 18:32:29 浏览: 309
HttpServletResponse
可以通过以下方式获取 HttpServletResponse 返回的结果:
1. 获取输出流对象:
```java
PrintWriter out = response.getWriter();
```
2. 将数据写入输出流中:
```java
out.write("Hello, World!");
```
3. 关闭输出流:
```java
out.close();
```
完整示例代码:
```java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
out.write("Hello, World!");
out.close();
}
```
阅读全文