HttpServletResponse写数据
时间: 2024-06-14 13:05:08 浏览: 30
通过HttpServletResponse对象可以将数据写入响应中,以发送给客户端。以下是两种写数据的方法:
1. 使用字符输出流将数据写入响应:
```java
PrintWriter writer = resp.getWriter();
writer.write("hello servlet!!!");
```
2. 使用sendRedirect方法将请求重定向到指定的URL:
```java
resp.sendRedirect("http://localhost:8888/servlet_war_exploded/httpServletResponse004");
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![application/x-zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)