我正在尝试在Netbeans中创建一个简单的MySQL,Java JDBC Web应用程序。 我希望根据当前会话中的状态变量显示不同的内容。我尝试了以下方法:
首先,我在.jsp页面中有以下代码:
<c:choose>
<c:when test="${sessionScope.Staff.getStatus() == staff.default_staff_status}">Default staff</c:when>
<c:when test="${sessionScope.Staff.getStatus() == staff.financial_staff_status}">Financial staff</c:when>
<c:when test="${sessionScope.Staff.getStatus() == staff.legal_staff_status}">Legal staff</c:when>
<c:otherwise>Secretarial staff</c:otherwise>
</c:choose>
其次,我在.jsp页面中有以下代码:
<c:if test = "${sessionScope.Staff.getStatus() == Staff.default_staff_status}" >
Default staff
</c:if>
<c:if test = "${sessionScope.Staff.getStatus() == Staff.financial_staff_status}" >
Financial staff
</c:if>
<c:if test = "${sessionScope.Staff.getStatus() == Staff.legal_staff_status}" >
Legal staff
</c:if>
<c:if test = "${sessionScope.Staff.getStatus() == Staff.secretarial_staff_status}" >
Secretarial staff
</c:if>
sessionScope.Staff将对象StaffData定义为:
public class StaffData
{
protected final byte default_staff_status = 0;
protected final byte financial_staff_status = 1;
protected final byte legal_staff_status = 2;
protected final byte secretarial_staff_status = 3;
private byte status;
//Other data
StaffData()
{
//Constructor
}
//Other methods
public byte getStatus()
{
return this.status;
}
public byte getDefault_staff_status()
{
return this.default_staff_status;
}
public byte getFinancial_staff_status()
{
return this.financial_staff_status;
}
public byte getLegal_staff_status()
{
return this.legal_staff_status;
}
public byte getSecretarial_staff_status()
{
return this.secretarial_staff_status;
}
}
通过这两种方法,我的输出是:
Default staff Financial staff Legal staff Secretarial staff
但是,只应打印其中一个。所有getter函数都是公共的并且已正确定义。为什么我看到所有的线条被打印出来?
答案 0 :(得分:2)
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
不知道为什么我没有收到任何错误