JSP useBean question

T

tomk4567

Newbie with JSP / JavaBeans.

Wondering where the compiled class code goes for a custom written Bean? I
placed the compiled Bean class in the JSP folder and the Servlet folder in
appropriate tomcat dir. But I am still getting a 'Unable to load class for
JSP' error from Apache.

When I use a standard java class such as java.util.Date there is no problem
getting the simple JSP to run correctly.

I am sure this is a simple question. Thanks for any help.

--

code:

Circle.class code (my simple Bean)

public class Circle {
double radius;
double area;
public void setRadius(double r) {
radius = r;
}
public double getRadius() {
return radius;
}
public void setArea(double a) {
area = a;
}
public double getArea() {
return area;
}
}

--

JSP code:

<html><head><title>
JSP calling a custom JavaBean
</title></head>
<body>
<center>

<jsp:useBean name="circle1" class="Circle" >
<jsp:setProperty name="circle1" property="radius" value="2">
Area = <jsp:getProperty name="circle1" property="area">

</center>
</body>
</html>
 
C

cld71

Newbie with JSP / JavaBeans.

Wondering where the compiled class code goes for a custom written Bean? I
placed the compiled Bean class in the JSP folder and the Servlet folder in
appropriate tomcat dir. But I am still getting a 'Unable to load class for
JSP' error from Apache.

It should be placed at
$TOMCAT_HOME/webapps/YOUR_SITES_DIR/WEB-INF/classes/shape/Circle.class
When I use a standard java class such as java.util.Date there is no problem
getting the simple JSP to run correctly.

I am sure this is a simple question. Thanks for any help.

--

code:

Circle.class code (my simple Bean)

add this at the top

package shape;

public class Circle {
double radius;
double area;

public void setRadius(double r) {
radius = r;
}

public double getRadius() {
return radius;
}

public void setArea(double a) {
area = a;
}

public double getArea() {
return area;
}
}

And change your JSP code to this:

<%@page language="java"%>
<html><head><title>
JSP calling a custom JavaBean
</title></head>
<body>
<center>
<jsp:useBean id="circle1" scope="page" class="shape.Circle">
<jsp:setProperty name="circle1" property="radius" value="2"/>
Area = <jsp:getProperty name="circle1" property="area"/>
</jsp:useBean>
</center>
</body>
</html>

I forgot why, but JSP doesn't see Objects unless there are in a package.

Here are some links with a Syntax Card to make it easier with your <jsp>
tags http://java.sun.com/products/jsp/docs.html.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top