Response.java 576 B

123456789101112131415161718
  1. package cn.hhj.bio.tomcat.http;
  2. import java.io.OutputStream;
  3. public class Response {
  4. private OutputStream out;
  5. public Response(OutputStream out){
  6. this.out = out;
  7. }
  8. public void write(String s) throws Exception {
  9. StringBuilder sb = new StringBuilder();
  10. sb.append("HTTP/1.1 200 OK\n") // 状态码,表示响应成功
  11. .append("Content-Type: text/html;\n") // 返回值类型
  12. .append("\r\n") // 分隔符
  13. .append(s); // 返回值内容
  14. out.write(sb.toString().getBytes());
  15. }
  16. }