1

我写了一小段代码来理解会话......这是代码

public class SessionServlet extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response) throws    IOException,ServletException
{
PrintWriter out=response.getWriter();
HttpSession session=request.getSession();
if(session.isNew())
{
out.println("Client has not responded");

}
else out.println("Client has responded");
}
}

以我的理解,在第一次运行我的程序时,它应该“客户没有响应”,但是它打印了第一条语句......可以解释为什么它会这样做。

4

2 回答 2

0

If its JSP your accessing before the request reaches the servlet , you should probably check for a setting

<%@ page session="true" %>

in JSP.

Change it to <%@ page session="false" %> , because having it true , means JSP will participate in a session and no session found it will create one , even before the request reaches the servlet

于 2013-02-11T07:54:41.930 回答
0

您的代码似乎没问题,要对其进行测试,请确保您清除浏览器缓存/cookie以确保删除旧会话。

于 2013-02-10T23:19:40.763 回答