5,657
社区成员
发帖
与我相关
我的任务
分享public class ExitServletListener implements HttpSessionListener {
int i =0;
@Override
public void sessionCreated(HttpSessionEvent se) {
// TODO Auto-generated method stub
System.out.println("session created");
i++;
se.getSession().getServletContext().setAttribute("count", i);
}
@Override
public void sessionDestroyed(HttpSessionEvent se) {
// TODO Auto-generated method stub
System.out.println("session destoryed");
i--;
se.getSession().getServletContext().setAttribute("count", i);
}
}
<body>
<h1>${count}</h1>
<a href="ExitServlet">安全退出</a>
</body>
public class ExitServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.getSession().invalidate();
response.sendRedirect("show.jsp");
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
发布之后访问,控制台没有任何输出,访问页面只有一个超链接,h3标签没有内容。只有点超链接把session失效之后控制台才有输出,jsp页面h3标签才有内容。这是为什么?