案例:请求重定向(相当于超链接跳转页面)


package com.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* 案例:请求重定向(相当于超链接跳转页面)
* @author zhiyong
*
*/
public class ResponseDemo2 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

/*
* 需求:跳转到ad.html
* 使用请求重定向:发送一个302状态码+location响应头
*/
/* response.setStatus(302);
response.setHeader("Location", "/web161115/ad.html");*/

//使用请求重定向简化书写
response.sendRedirect("/web161115/ad.html");
}
}