-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathByte_stream.java
More file actions
27 lines (23 loc) · 920 Bytes
/
Byte_stream.java
File metadata and controls
27 lines (23 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package cn.web.response.servlet;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/byte_stream")
public class Byte_stream extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("text/html;charset=utf-8");
//1.获取字节输出流
ServletOutputStream sos = resp.getOutputStream();
//2.输出数据
sos.write("哈哈".getBytes("utf-8"));
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
this.doPost(req, resp);
}
}