我是Servlet和JSP的新手,我想在我的web应用程序运行后抓取所有的cookies,所以一旦我的web应用程序运行,我就使用ServletContextListener来部署它里面的东西,那么我如何才能获得它里面的所有cookies呢?我正在尝试做以下几件事:
public class listener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent sce) {
HttpServletRequest request ;
Cookie s[]=request.getCookies();
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
}}发布于 2016-03-14 22:42:02
您可能不需要所有用户的所有cookies,但您需要特定请求的cookie。您可以在HttpServlet的doGet()或doPost()方法中获取它们,具体取决于请求类型:
public class TestServlet extends HttpServlet {
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException {
Cookie[] cookies = request.getCookies();
//...
}
}https://stackoverflow.com/questions/35990167
复制相似问题