一:Reponse对象的概念
当客户端发送http请求时,服务器端会对每一次请求,创建request对象和response对象。
response对象包括三个部分:响应头、响应状态码以及响应体
二:response对象案例分析
1:向客户端输出中文数据
1 package com.hlcui.servlet; 2 3 import java.io.IOException; 4 import java.io.OutputStream; 5 import java.io.PrintWriter; 6 7 import javax.servlet.ServletException; 8 import javax.servlet.http.HttpServlet; 9 import javax.servlet.http.HttpServletRequest; 10 import javax.servlet.http.HttpServletResponse; 11 12 public class ServletDemo6 extends HttpServlet { 13 14 public void doGet(HttpServletRequest request, HttpServletResponse response) 15 throws ServletException, IOException { 16 17 String data = "好好学习!"; 18 //获取向客户端写数据的输出流 19 OutputStream out = response.getOutputStream(); 20 out.write(data.getBytes()); 21 } 22 23 public void doPost(HttpServletRequest request, HttpServletResponse response) 24 throws ServletException, IOException { 25 doGet(request,response); 26 } 27 28 }