响应,表示了服务器收到了请求,处理完成后,把处理的结果告知用户
响应对象也是Servlet规范中定义的,它包括了协议无关的和协议相关的
协议无关对象:ServletResponse接口
协议相关对象:HttpServletResponse接口
状态码
状态码首位含义
处理响应字节输出流中文问题
public class ResponseDemo1 extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response){ response.setHeader("Content-Type","text/html;charset=UTF-8"); response.ContentType("text/html;charset=Utf-8"); } public void doGet(HttpServletRequest request, HttpServletResponse response){ doPost(request,response); } }
重定向(地址栏会发生变化)
public class ResponseDemo6 extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response){ response.sendRedirect("response"); } public void doGet(HttpServletRequest request, HttpServletResponse response){ doPost(request,response); } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)