当前位置:编程学习 > JAVA >>

{附有代码}保存session后,不关闭此页面,然后重新打开同一个页面,保存的session为空是什么原因?

####################index.jsp##################################
<%@ page language="java"
    import="java.sql.*, java.util.*, 

com.sun.rowset.CachedRowSetImpl,com.hisense.HiLib.DataBase.*"
    errorPage="./webs/form/error.jsp" 
    pageEncoding="gbk"    
%>
<%
    String basePath = new String("./");
    session.setAttribute("basePath", basePath);
%>
<jsp:useBean id="book" class="com.hisense.HiLib.DataBase.Book" />
<html>
   <head>
      <title> 海信网上图书馆 HiLib </title>
   </head>
   
   <body>
      <table border="2" cellpadding="0" cellspacing="0" width="100%">
         <tr>
            <td colspan="2" width="100%">
               <jsp:include page='<%= session.getAttribute("basePath") + 

"/webs/form/logo.jsp" %>' flush="true" />
            </td>
         </tr>
         <tr>
            <td width="23%">
               <jsp:include page='<%= session.getAttribute("basePath") + 

"webs/login/login.jsp" %>' flush="true" />
            </td>
            <td rowspan="2" valign="top" width="77%">
               <jsp:include page='<%= session.getAttribute("basePath") + 

"webs/news/news.jsp" %>' flush="true" />
            </td>
         </tr>
         <tr>
            <td width="23%">
               <jsp:include page='<%= session.getAttribute("basePath") + 

"webs/form/functionLink.jsp" %>' flush="true" />
            </td>
         </tr>
      </table>
    </body>
</html>

###################################login.jsp######################################
<%@ page pageEncoding="gbk"%>
<%
          String path = request.getContextPath();
%>
<form method="post" action='<%= session.getAttribute("basePath") + "webs/login/switcher.jsp" %>' >
   <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <% 
         if(session.getAttribute("isRegistered")!=null){
         if(session.getAttribute("isRegistered").toString().equals("yes")){
      %>
      <tr>
         <td>
             欢迎<font  color="blue"> <b><%= session.getAttribute("userName") %> </b></font> 光临!<br>
             这是您第 <%= session.getAttribute("totalRegistered") %> 次光临本站!<br>
             祝您工作愉快!
         </td>
      </tr>
    </table>
      <%
         }
         else if(session.getAttribute("isRegistered").toString().equals("no")){
      %>
      <tr>
         <td width="100%" ><br></td>
      </tr>
      <tr>
         <td>用户名:</td>
         <td><input name="userName" type="text"></td>
      </tr>
      <tr>
         <td> 密码:</td>
         <td><input name="passWord" type="password"></td>
      </tr>
      <tr>
         <td><input name="loginSubmit" type="submit" value="登录"></td>
         <td><input name="registerSubmit" type="submit" value="注册"></td>
      </tr>
    </table>
      <%
         }
      }
      else{
      %>
      <tr>
         <td width="100%" ><br></td>
      </tr>
      <tr>
         <td>用户名:</td>
         <td><input name="userName" type="text"></td>
      </tr>
      <tr>
         <td> 密码:</td>
         <td><input name="passWord" type="password"></td>
      </tr>
      <tr>
         <td><input name="loginSubmit" type="submit" value="登录"></td>
         <td><input name="registerSubmit" type="submit" value="注册"></td>
      </tr>
    </table>
      <%
      }
      %>
</form>

##########################################################################
就是打开页面后,复制url粘贴到地址栏,点击进入后,保存的url为空,刷新后就不为空了 --------------------编程问答-------------------- 哪个页面? --------------------编程问答-------------------- --------------------编程问答-------------------- 首先打开index.jsp登陆
登陆后进入loginResult.jsp
然后在地址栏里打出index.jsp
打开的页面里session里用户信息为空(问题出在这里)
刷新一下用户信息又出来了(关于这一点真想把电脑砸了) --------------------编程问答-------------------- qq群:199632302
补充:Java ,  Web 开发
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,