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
SteveFarndon2000Managing DirectorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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


Cheers!
0
kiranhkCommented:
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}"/>
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

TimYatesCommented:
petmagdy's comment of

    <%=item.quantity %>

should probably be:

    <%= item.getQuantity() %>
0
petmagdyCommented:
yes TimYates I supposed it is public member field, and their was no indication in steve Question that their is a function called getQuantity()
0
TimYatesCommented:
${item.quantity} in JSTL would call a getQuantity() method...
0
siliconeagleCommented:
to use  ${item.quantity} you need to be using a JSP2.0 compliant web container - such as tomcat 5.0 up. The Expressin Langauge(EL) (which is the ${<expr>} syntax) is new to JSP 2.0.

<%= item.getQuantity() %> is the older style JSP expression.

So if you are using tomcat 5.0 up ${item.quantity} should work otherwise you would need to use <%= item.getQuantity() %> or kiranhk solution above.
0
siliconeagleCommented:
oops there is a bit more too it actually,
 you need to do a couple of things to enable the expression language(EL):-

in the JSP page check for this tag:-
<%@ page isELIgnored="false" %>
to put in the jsp page - then ${item.quantity} should work.

if you want EL enabled globally then in web.xml you need to check (or add) this XML:-
<jsp-config>
                <jsp-property-group>
                        <url-pattern>*.jsp</url-pattern>
                        <el-ignored>false</el-ignored>
                        <scripting-enabled>true</scripting-enabled>
                </jsp-property-group>
</jsp-config>


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.