Link to home
Start Free TrialLog in
Avatar of SteveFarndon2000
SteveFarndon2000Flag for United Kingdom of Great Britain and Northern Ireland

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
Avatar of petmagdy
petmagdy
Flag of Canada image

Hi SteveFarndon2000,
it is:
 <tr>
    <td align="right" bgcolor="#ffffff">
    <%=item.quantity %>
    </td>


Cheers!
Avatar of kiranhk
kiranhk

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}"/>
Avatar of TimYates
petmagdy's comment of

    <%=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
Avatar of siliconeagle
siliconeagle

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial