我在單個頁面中設置了許多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>
在附註中,您可以用'' />「>' –
@KevinBowersox我還注意到,該部分的值成爲會話id爲什麼會發生這種情況? – PeterJohn