设置了session.setMaxInactiveInterval(10)之后,过了10秒用户没活动,用户的相关信息确实被服务器删除了,但是我做jsp网页的时候,如何判断呢?是不是当链接到另一页的时候,判断用户变量是否还存在?

解决方案 »

  1.   

    if((String)session.getAttribute("SessionName") == null){
      out.println(""yes);
    }else{
      out.println("no");
    }
      

  2.   

    楼上说的不错。
    看看这个函数对你有用吗?
    getLastAccessedTime()
      

  3.   

    <%@ page contentType="text/html;charset=gb2312"language="java"import="java.sql.*" %>
    <html>
    <head>
    </head>
    <%
     String username=(String)session.getAttribute("usersession");
     if(username==null){
    %>
          <script lanuage=javascript>
    alert("连接超时,\n请您重新登录!!");
    setTimeout("top.location.href='index.htm'","5");
    </script>
          <%
    }else{%>
      

  4.   

    woxinyongheng(枚枚),是不是应该在链接到这一页的上一页中加入语句:session.setMaxInactiveInterval(10)???
    否则session.getAttribute("usersession")永远都会存在的!!!