[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Syntax problems when trying to print out a value of an object's property.

Posted on 2004-11-03
8
Medium Priority
?
227 Views
Last Modified: 2013-11-24
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
0
Comment
Question by:SteveFarndon2000
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 13

Expert Comment

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


Cheers!
0
 
LVL 8

Expert Comment

by:kiranhk
ID: 12486324
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
 
LVL 8

Expert Comment

by:kiranhk
ID: 12486539
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Expert Comment

by:TimYates
ID: 12491260
petmagdy's comment of

    <%=item.quantity %>

should probably be:

    <%= item.getQuantity() %>
0
 
LVL 13

Expert Comment

by:petmagdy
ID: 12491302
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
 
LVL 35

Expert Comment

by:TimYates
ID: 12491315
${item.quantity} in JSTL would call a getQuantity() method...
0
 
LVL 2

Assisted Solution

by:siliconeagle
siliconeagle earned 1500 total points
ID: 12491470
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
 
LVL 2

Accepted Solution

by:
siliconeagle earned 1500 total points
ID: 12491681
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question