这个程序是记录访问session的次数 如果在一个浏览器窗口中不停的刷新 次数会叠加 但是如果另外开一个窗口(不是子窗口 是另外起的IE) 次数依然会在原来的基础上叠加!! session不是只对一个浏览器窗口的吗 为什么另外开的窗口还能拥有相同的sessionID?? import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.*;public class ShowSession extends HttpServlet { @Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
HttpSession mysession = request.getSession(true);
Integer a = (Integer)mysession.getAttribute("accesscount");
if(a==null) {
a = new Integer(0);
mysession.setAttribute("accesscount", a);
}
else {
a = new Integer(a.intValue()+1);
mysession.setAttribute("accesscount", a);
}
pw.println("<html><head>\n"
+ "<title>showsession</title>\n"
+ "</head>\n"
+ "<body>\n"
+ "<table><tr><td>\n"
+ "session id:</td><td>"
+ mysession.getId()
+ "</td>\n"
+ "<tr><td>\n"
+ "accesscount:</td><td>"
+ mysession.getAttribute("accesscount")
+ "</td></tr></table>\n"
+ "</body></html>\n");
}}
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.*;public class ShowSession extends HttpServlet { @Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
HttpSession mysession = request.getSession(true);
Integer a = (Integer)mysession.getAttribute("accesscount");
if(a==null) {
a = new Integer(0);
mysession.setAttribute("accesscount", a);
}
else {
a = new Integer(a.intValue()+1);
mysession.setAttribute("accesscount", a);
}
pw.println("<html><head>\n"
+ "<title>showsession</title>\n"
+ "</head>\n"
+ "<body>\n"
+ "<table><tr><td>\n"
+ "session id:</td><td>"
+ mysession.getId()
+ "</td>\n"
+ "<tr><td>\n"
+ "accesscount:</td><td>"
+ mysession.getAttribute("accesscount")
+ "</td></tr></table>\n"
+ "</body></html>\n");
}}
以前我也碰到类似的问题
IE8之前的版本每个独立的一个IE窗体在服务器存在一个独立的Session
IE8之后只要IE程序问全部关闭都会视为同一个Session
火狐或者google浏览也是的