我试图将条件写入jstl if tag,
<c:forEach var="ledg" items="user_ledgers">
<c:if test="${ledg.transactionID == param['trns']}">
<c:out value="${ledg.name}"/>
</c:if>
</c:forEach>
Ledg是分类帐类的对象,transactionID是long类型的字段。
我在运行时发现了这个错误。
javax.el.PropertyNotFoundException: Property 'transactionID' not found on type java.lang.String
我尝试通过多种方式将transactioID值转换为String。但是没有工作
字符串连接
<c:if test="${(ledg.transactionID+’’) == param['trns']}">
使用自定义标记
<c:set var="equals" scope="page">
<z:doTheyEquals v1="${ledg.transactionID}" v2="${param['trns']}"/>
</c:set>
它还需要String类型。
将user_ledges设置为会话范围
LedgerDAO ledg = Data.getLedgerDAO();
List ledgers = ledg.getLedgers(u);
session.setAttribute("user_ledgers",ledgers);
getLedgers()
public List<Ledger> getLedgers(User u) {
List ledgers = new ArrayList<Ledger>();
try (Connection conn = pool.getConnection()){
PreparedStatement query = conn.prepareStatement("SELECT * FROM user_ledgers INNER JOIN ledgers ON user_ledgers.l_id = ledgers.id WHERE user_ledgers.u_id=? ORDER BY name ASC;");
query.setString(1,u.getId()+"");
ResultSet rs = query.executeQuery();
while(rs.next()){
Ledger l = new Ledger();
l.setId(rs.getLong(4));
l.setName(rs.getString(5));
l.setLayout(rs.getString(7));
l.setTransactionID(rs.getLong(3));
l.setType(rs.getString(6));
ledgers.add(l);
}
} catch (Exception e) {
e.printStackTrace();
ledgers=null;
}
return ledgers;
}
有任何帮助吗?谢谢。
答案 0 :(得分:0)
使用此:
<c:forEach var="ledg" items="${sessionScope.user_ledgers}">
<c:if test="${ledg.transactionID == param['trns']}">
<c:out value="${ledg.name}"/>
</c:if>
</c:forEach>