http---响应信息案例一:实现请求重定向(相当于超链接跳转页面)
实现从当前页面跳转到“/day08_web/testParam.html”页面
实现的主程序:Demo_Response2.java
package Response;
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;
/*
* 案例一:请求重定向(相当于超链接跳转页面)
*/
public class Demo_Response2 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
/*
* 需求:跳转到adv.html
* 使用请求重定向:发送一个302状态码+location的响应头
*/
// response.setStatus(302);
// response.setHeader("location", "/day08_web/testParam.html");
//请求重定向的简化写法(相当于上面的两步)
response.sendRedirect("/day08_web/testParam.html");
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
}