【发布时间】:2015-01-20 05:18:38
【问题描述】:
我正在尝试在 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 函数都是公开的并且被正确定义。为什么我看到所有行都在打印?
【问题讨论】:
-
好像你还没有应用那里提供的解决方案。
-
我确实输入了 test 属性。我没有将 sessionScope.Staff.getStatus() 更改为 Staff.status,因为我想明确声明我正在使用会话变量。我还为 Financial_staff_status 添加了 getter 方法。但是,这如何解释我得到的输出?
标签: java mysql jsp if-statement el