2013-02-05 107 views
0

我在單個頁面中設置了許多c:set聲明。另外,我將我的roleId設置爲我的會話。現在,當我讓其他c:設置我的會話角色受到影響。我確認這是因爲我在我的頁面中顯示了我的會話ID。登錄後我的會話ID是正確的,但當我刷新頁面時,我的會話ID更改。爲什麼呢?這是我的代碼爲什麼JSTL c:設置聲明會影響我的會話

<%@page import="request.RequestDAO"%> 
<%@page import="request.RequestItems"%> 
<%@include file="/WEB-INF/common/taglibs.jsp"%> 
<%@ page import="message.MessageItems"%> 
<%@ page import="message.NewMessageDAO"%> 
<div id="menu-wrapper"> 

    <div id="menu"> 
     <span class="menu-header">Calendar</span> 
     <div id="adminCalendar"></div> 
    </div> 

    <div id="menu"> 
     <span class="menu-header">Directories <%=((Long) session.getAttribute("role")).longValue()%> </span> 
     <ul> 
      <li><a href="${pageContext.request.contextPath}/directory/list-of-registered-organizations">Organization </a></li> 
      <li><a href="${pageContext.request.contextPath}/directory/list-of-registered-medical-service">Medical Service</a></li> 
      <li><a href="${pageContext.request.contextPath}/directory/list-of-registered-evacuation-center">Evacuation Centers</a></li> 
      <li><a href="${pageContext.request.contextPath}/directory/list-of-registered-fire-suppression-group">Fire Suppression Groups</a></li> 
      <li><a href="${pageContext.request.contextPath}/directory/list-of-registered-medical-facilities">Medical Facilities</a></li> 
      <li><a href="${pageContext.request.contextPath}/directory/list-of-registered-rescue-organization">Rescue Organizations</a></li> 
      <li><a href="${pageContext.request.contextPath}/directory/list-of-registered-agency">Agency</a></li> 
      <li><a href="${pageContext.request.contextPath}/directory/list-of-registered-schools">Schools</a></li> 
     </ul> 
    </div> 
    <c:set var="admin" scope="session" value='<%=((Long) session.getAttribute("role")).longValue()%>' /> 
    <c:if test="${admin == 121}"> 
     <div id="menu"> 
      <span class="menu-header">Registration</span> 
      <ul> 
       <li><a href="${pageContext.request.contextPath}/registration/organization-registry">Organization Registry </a></li> 
       <li><a href="${pageContext.request.contextPath}/registration/emergency-medical-service">Emergency Medical Service Registry</a></li> 
       <li><a href="${pageContext.request.contextPath}/registration/register-evacuation-center">Evacuation Centers Registry</a></li> 
       <li><a href="${pageContext.request.contextPath}/registration/register-fire-suppression-group">Fire Suppression Group Registry</a></li> 
       <li><a href="${pageContext.request.contextPath}/registration/register-medical-facilities">Medical Facilities Registry</a></li> 
       <li><a href="${pageContext.request.contextPath}/registration/register-rescue-organizations">Rescue Organizations Registry</a></li> 
       <li><a href="${pageContext.request.contextPath}/registration/agency-registration">Agency Registry</a></li> 
       <li><a href="${pageContext.request.contextPath}/registration/school-registration">School Registry</a></li> 

      </ul> 
     </div> 
    </c:if> 

    <% 
     long id = ((Long) session.getAttribute("userId")).longValue(); 
     MessageItems message = new NewMessageDAO().NewMessages(id); 
     RequestItems NewRequest = new RequestDAO().NewRequests(id); 
    %> 

    <div id="menu"> 
     <span class="menu-header">User Option</span> 
     <ul> 
      <li><a href="${pageContext.request.contextPath}/registration/organization-registry">My Account</a></li> 
      <li><a href="${pageContext.request.contextPath}/registration/emergency-medical-service">Change Password</a></li> 
      <li><a href="${pageContext.request.contextPath}/message/inbox">My Messages 

      <c:set var="role" scope="session" value='<%=message.getNewMessages()%>' /> 
      <c:if test="${role == 0}"> 
       <li><a href="${pageContext.request.contextPath}/message/inbox">My Messages<label></label></a></li> 
      </c:if> 
      <c:if test="${role != 0}"> 
       <li style="font-weight: bold"><a href="${pageContext.request.contextPath}/message/inbox">My Messages <label>(<%=message.getNewMessages()%>) 
        </label></a></li> 
      </c:if> 

      <li><a href="${pageContext.request.contextPath}/message/new-message">Send Message</a></li> 


      <c:set var="role1" scope="session" value='<%=NewRequest.getNewRequest()%>' /> 
      <c:if test="${role1 == 0}"> 
       <li><a href="${pageContext.request.contextPath}/request/request-inbox">My Requests<label></label></a></li> 
      </c:if> 
      <c:if test="${role1 != 0}"> 
       <li style="font-weight: bold"><a href="${pageContext.request.contextPath}/request/request-inbox">My Requests <label>(<%=NewRequest.getNewRequest()%>) 
        </label></a></li> 
      </c:if> 
      <li><a href="${pageContext.request.contextPath}/request/new-request">Make Request</a></li> 

      <li><a href="${pageContext.request.contextPath}/request/request-inbox">My Requests</a></li> 



      <li><a href="${pageContext.request.contextPath}/action/add-user">Add user</a></li> 
      <li><a href="${pageContext.request.contextPath}/action/view-all-user">View user</a></li> 

     </ul> 
    </div> 
</div> 

回答

0

從目前的代碼中,我只能假設,這是因爲該行

<c:set var="role" scope="session" value='<%=message.getNewMessages()%>' /> 

從message.getNewMessages值(的),當你的頁面再次運行必須改變。

可能是由於MessageItems message = new NewMessageDAO().NewMessages(id);

但它不可能說沒有這些類的存在的代碼。

+0

該行message.getNewMessages()只返回未讀消息的數量...我無法弄清楚問題 – PeterJohn

+0

Then MessageItems message = new NewMessageDAO().NewMessages(id)必須改變未讀消息的數量。 – Thihara

+0

該行MessageItems消息= new NewMessageDAO()。NewMessages(id)調用基於會話userId計算未讀消息數的方法。 – PeterJohn

相關問題