Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with code in beginner book...

Status
Not open for further replies.

wvmikep

Programmer
Feb 26, 2001
35
US
I can't figure this one out:

I have the following bean:

/*
* CarBean.java
*
* Created on October 2, 2003, 8:36 PM
*/

package com.wrox.cars;
//package Templates.Beans;

import java.io.Serializable;
//import java.beans.*;

/**
*
* @author mike
*/
public class CarBean implements Serializable {

public CarBean() {
}

private String make = "Ford";

public String getMake() {
return make;
}

public void setMake(String make) {
this.make = make;
}

private double cost = 10000.00;
private double taxRate = 17.5;

public double getPrice() {
double price = (cost + (cost * (taxRate/100)));
return price;
}

private void setPrice(double newPrice) {
}
}

...and the following JSP page:

<%@page contentType=&quot;text/html&quot;%>
<html>
<head><title>Using a JavaBean</title></head>
<body>

<h2>Using a JavaBean</h2>

<jsp:useBean id=&quot;myCar&quot; class=&quot;com.wrox.cars.CarBean&quot; />

I have a <jsp:getProperty name=&quot;myCar&quot; property=&quot;make&quot; /> <br />

My car costs $<jsp:getProperty name=&quot;myCar&quot; property=&quot;price&quot; />

</body>
</html>

The problem is, I get:
500 Unhandled exception thrown from /begjsp-ch04/carPage2.jsp:12
Unhandled exception thrown from /begjsp-ch04/carPage2.jsp:12

If I delete the whole line in the JSP page that starts with &quot;My car costs...&quot; the error goes away. This code is straight from the book. Any ideas?

Thanks
 
Hi,

I copied your code and it ran fine for me. I think your JSP file cannot locate the compiled CarBean.class.

Output is
Using a JavaBean
I have a Ford
My car costs $11750.0

The Compiled class file should be under
<URWebApps>/WEB-INF/classes/com/wrox/cars/CarBean.class

Just make sure ..

Cheers
-Venu
 
It finds the class. The odd thing is, if I comment out that second jsp:getProperty tag it works. I even tried <%= getPrice() %> instead and that didn't work.
 
Its probably something to do with the &quot;$&quot; sign. What UTF encoding are you using ?

>>>> I even tried <%= getPrice() %> instead and that didn't work.
This isn't going to work because you have not specified which class the getPrice() method belongs to ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top