• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getProperty() problem

 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I receive this error message when I run the following jsp:
org.apache.jasper.JasperException: Cannot find a method to read property 'lowerLimit' in a bean of type 'num.NumberGuessBean'
jsp:

<%@ page import = "num.NumberGuessBean" %>
<jsp:useBean id="numguess" class="num.NumberGuessBean" scope="session"/>
<jsp:setProperty name="numguess" property="*"/>
<html>
<head><title>Number Guess</title></head>
<body bgcolor="white">
<font size=4>
<% if (numguess.getSuccess()) { %>
Congratulations! You got it.
And after just <%= numguess.getNumGuesses() %> tries.<p>
<% numguess.reset(); %>
Care to <a href="numguess.jsp">try again</a>?
<% } else if (numguess.getNumGuesses() == 0) { %>
Welcome to the Number Guess game.<p>
Play with default limits ( a number between 0 and 100)<p>
or enter upper and lower limits.<p>

<form method=get>
Play with defaults?: <input type=radio name=default value="yes">Yes
<input type=radio name=default value="no">No
<\form>

<% if (numguess.getRadio().equals("no")) { %>

<form method=get>
Enter upper limit:<input type=text name=upperLimit>
Enter lower limit:<input type=text name=lowerLimit>
<\form>

<% numguess.reset(); %>

<% } %>

<form method=get>
What's your guess? <input type=text name=guess>
<input type=submit value="Submit">
</form>
<% } else { %>
Good guess, but nope. Try <b><%= numguess.getHint() %></b>.
You have made <%= numguess.getNumGuesses() %> guesses.<p>
I'm thinking of a number between <jsp:getProperty name="numguess" property="lowerLimit"/> and <jsp:getProperty name="numguess" property="upperLimit"/>.<p>
<form method=get>
What's your guess? <input type=text name=guess>
<input type=submit value="Submit">
</form>
<% } %>
</font>
</body>
</html>
the relevant part of the bean:
package num;
import java.util.*;
public class NumberGuessBean {
int answer;
boolean success;
String hint;
int numGuesses;
String radiochoice;
int lowerLimit=0;
int upperLimit=100;
String error;
public NumberGuessBean() {
reset();
}
public void setGuess(String guess) {
numGuesses++;
int g;
try {
g = Integer.parseInt(guess);
}
catch (NumberFormatException e) {
g = -1;
}
if (g == answer) {
success = true;
}
else if (g == -1) {
hint = "a number next time";
}
else if (g < answer) {
hint = "higher";
}
else if (g > answer) {
hint = "lower";
}
}
public void setRadio(String s) {
radiochoice=s;
}
public String getRadio() {
return radiochoice;
}
public void setLowerLimit( String lowerLimit) {
int l;
try {
l=Integer.parseInt(lowerLimit);
}
catch(NumberFormatException e) {
l=-1;
}
if (l==-1) {
error= "Please enter a number";
}
else {
this.lowerLimit=l;
}
}
public int getLowerLimit() {
return lowerLimit;
}
public void setUpperLimit(String upperLimit) {
int l;
try {
l=Integer.parseInt(upperLimit);
}
catch(NumberFormatException e) {
l=-1;
}
if(l==-1) {
error="Please enter a number";
}
else {
this.upperLimit=l;
}
}
public int getUpperLimit() {
return upperLimit;
}
Any help would be appreciated
 
reply
    Bookmark Topic Watch Topic
  • New Topic