This week's giveaway is in the Java/Jakarta EE forum.
We're giving away four copies of Java EE 8 High Performance and have Romain Manni-Bucau on-line!
See welcome thread
Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

jsp weekend crash course - chapter 11  RSS feed

Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok. i have isolated the error (property not found) to the line in my .jsp which tries to jsp:getProperty. Trouble is, even if it doesn't SET the property (value), it should at least FIND the property, NO? I have tried using initCap to differeniate the parameter with the property. Still no luck. Here is the source:
Can anyone help?
First: FruitOrder.html
(note: i placed the jsp:useBean thinking it "instances" it here!?
<HTML> <body> <h1>Fruit Order Form</h1>
<jsp:useBean id="orderedFruit" scope="request" class="aPack.Fruit" />
Fruit: Mango<br> Color: Orange<br> Price Per Pound: $5.95 <br>
<form action="confirm.jsp" method="post">
Number of pounds: <input type="text" name="Quantity"><br>
<input type="submit" value="Order Fruit" >
</form> </body> </html>
Now--- the (class). has set and get functions
package aPack;
public class Fruit {
private String fruitName;
private String color;
private float price;
private int Quantity;
private boolean isCitrus;
public String getFruitName(){return this.fruitName;}
public void setFruitName(String name){this.fruitName=name;}
public int getQuantityInPounds(){return this.Quantity;}
public void setQuantityInPounds(int Quantity){this.Quantity=Quantity;}
public String getColor(){return this.color;}
public void setColor(String color){this.color=color;}
public float getPrice(){return this.price;}
public void setPrice(float price){this.price=price;}
public boolean isCitrus(){ return this.isCitrus; }
public void setCitrus(boolean isCitrus){
and finally the pain/problem: confirm.jsp
<jsp:useBean id="orderedFruit" scope="request" class="aPack.Fruit" />
<jsp:setProperty name="orderedFruit" property="*" />
<HTML> <body> <h1>Your Fruit Order</h1> <br><br>
Fruit: <jsp:getProperty name="orderedFruit" property="fruitName" /><br>
Color: <jsp:getProperty name="orderedFruit" property="color" /><br>
Price: $<jsp:getProperty name="orderedFruit" property="price" /><br>
------------------i get the error on this next line:
------------------quanity not found (tried with/out capital Q)
Quantity: <jsp:getProperty name="orderedFruit" property="Quantity" /> <br>
Total: <%=orderedFruit.getPrice()*orderedFruit.getQuantityInPounds() %> <p></p>
<a href="FruitOrder.html">Return to order form to adjust quantity</a>
<jsp:setProperty name="orderedFruit" property="fruitName" value="Mango" />
<jsp:setProperty name="orderedFruit" property="color" value="Orange" />
<jsp:setProperty name="orderedFruit" property="price" value="5.95" />
<jsp:setProperty name="orderedFruit" property="quantity" param="quantity" />
Author and all-around good cowpoke
Posts: 13078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The rule for properties is that you name the instance variable with a lower case letter and the get method with upper.
Therefore change your declaration of quantity :
private int quantity ;
public int getQuantity() { return quantity ; }
author of:
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. Although it really does not make any sense to me! I removed the capitals from all places that had the word "Quantity". Then I replaced setQuantityInPounds to just setQuantity (same with getQ...). The only conclusion I can gather is that --- there is a direct relationship from the instance variable name (quantity) and the function (set or get), and therefore placing a capital when combining setQuantity and getQuantity seems to work!
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

your name doesn't agree with the javaranch guidelines on names.
please take a moment and re-register after reviewing
the guidelines at
thanks for your cooperation.
- satya
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!