小编典典

JSTL sql:查询变量

jsp

我在JSP文件中编写了以下代码:

<c:catch var="e">
    <%
        int accountNumber = Integer.parseInt(request.getParameter("accountNumber"));
        int depositAmount = Integer.parseInt(request.getParameter("depositAmount"));
    %>
    <sql:query var='account' dataSource="jdbc/bank">
        select * from account where AccountNumber=<%= accountNumber %>      
    </sql:query>
    <c:choose>
        <c:when test="${account.first() == false}">
            <p>Account not found</p>
        </c:when>
        <c:otherwise>
            <h3>Deposit Made</h3>
            <p>Account number: <%= accountNumber %></p>
            <p>Deposit amount: <%= depositAmount %></p>
            <p>New balance: </p>
        </c:otherwise>
    </c:choose>
</c:catch>


<c:if test="${e != null}">
    error
</c:if>

我遇到的问题是以下代码引发了javax.el.MethodNotFoundException:无法找到具有[0]参数异常的方法[first]:

<c:when test="${account.first() == false}">
  <p>Account not found</p>
</c:when>

我需要访问sql:query中的account变量,以便可以检查是否存在第一行。


阅读 350

收藏
2020-06-10

共1个答案

小编典典

<sql:query var='account' dataSource="jdbc/bank">

根据<sql:query>文档accountjavax.servlet.jsp.jstl.sql.Result

<c:when test="${account.first() == false}">

按照类的javadoc,该类没有first()方法。但是,有一种getRowCount()方法。我建议改用它。

<c:when test="${account.rowCount == 0}">
2020-06-10