JSTL 变量不起作用
我编写了以下代码:
<%
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:forEach var="result" begin="0" items="${account.rows}">
<c:set var="balance" value="${ result.balance + depositAmount }" />
<c:out value="${ balance }" />
</c:forEach>
问题是对于
它实际上并没有将两个值加在一起。
我假设 DepositAmount 不被识别?我不知道为什么。
有人可以解释一下如何使用 JSTL 获取请求参数(余额)并将其添加到查询中获得的余额中吗?
这是我必须使用 JSP 的家庭作业。
谢谢
I wrote the following code:
<%
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:forEach var="result" begin="0" items="${account.rows}">
<c:set var="balance" value="${ result.balance + depositAmount }" />
<c:out value="${ balance }" />
</c:forEach>
The problem is that for <c:set var="balance" />
it isn't actually adding the two values together.
I'm assuming that depositAmount isn't recognized? I'm not sure why.
Can someone please explain how I can use JSTL to get the request parameter (balance) and add it to the balance obtained in the query?
This is a homework assignment where I must use JSP.
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Scriptlet(那些
<% %>
事物)和 EL(那些${}
事物)不共享相同的变量范围。摆脱 scriptlet 并仅使用 EL。请求参数在 EL 中,只需
${param.name}
即可获取。Scriptlets (those
<% %>
things) and EL (those${}
things) doesn't share the same variable scope.Get rid of scriptlets and use EL only. Request parameters are in EL available by just
${param.name}
.