SteveFarndon2000
asked on
Syntax problems when trying to print out a value of an object's property.
Hello All,
I'm new to JSP and I'm trying to work through some text book examples.
Every time I try to use the ${} construct (see example below) the JSP comiler just doesn't translate the contents into a value. In this example I just get ${item.quantity} (literally!) on the web page.
<%
Iterator i = cart.getItems().iterator() ;
while (i.hasNext()) {
ShoppingCartItem item =
(ShoppingCartItem)i.next() ;
...
%>
<tr>
<td align="right" bgcolor="#ffffff">
${item.quantity}
</td>
...
<%
}
%>
What am I doing wrong?
cheers
Stephen
I'm new to JSP and I'm trying to work through some text book examples.
Every time I try to use the ${} construct (see example below) the JSP comiler just doesn't translate the contents into a value. In this example I just get ${item.quantity} (literally!) on the web page.
<%
Iterator i = cart.getItems().iterator()
while (i.hasNext()) {
ShoppingCartItem item =
(ShoppingCartItem)i.next()
...
%>
<tr>
<td align="right" bgcolor="#ffffff">
${item.quantity}
</td>
...
<%
}
%>
What am I doing wrong?
cheers
Stephen
you need to have the jstl jar file in the lib directory of your web app. also there should be an entry in the web.xml for the tld file.
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<c:out value="${item.quantity}"/>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<c:out value="${item.quantity}"/>
petmagdy's comment of
<%=item.quantity %>
should probably be:
<%= item.getQuantity() %>
<%=item.quantity %>
should probably be:
<%= item.getQuantity() %>
yes TimYates I supposed it is public member field, and their was no indication in steve Question that their is a function called getQuantity()
${item.quantity} in JSTL would call a getQuantity() method...
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
it is:
<tr>
<td align="right" bgcolor="#ffffff">
<%=item.quantity %>
</td>
Cheers!