package pm_cn.itcast.cookie; |
import java.io.IOException; |
import javax.servlet.ServletException; |
import javax.servlet.http.Cookie; |
import javax.servlet.http.HttpServlet; |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletResponse; |
public class ClearRecordsServlet extends HttpServlet { |
public void doGet(HttpServletRequest request, HttpServletResponse response) |
throws ServletException, IOException { |
// 删除 持久 化 cookie, 清除 商品的 浏览 记录 |
|
Cookie cookie = new Cookie( "history" , "" ); |
|
// 有效期 设置 为 0 或 -1 |
cookie.setMaxAge( 0 ); |
|
// 有效 路径 要 一致 ,否则 不会 删除 . |
cookie.setPath( "/" ); |
|
response.addCookie(cookie); |
|
// 删除 后 返回 , 让其 重定向 到 这个 商品 列表的 jsp 页面 |
response.sendRedirect( "/day12/cookie/products.jsp" ); |
|
} |
public void doPost(HttpServletRequest request, HttpServletResponse response) |
throws ServletException, IOException { |
doGet(request, response); |
} |
} |