For Programmers: Free Programming Magazines  


Home > Archive > Java Beans > September 2005 > JSP useBean question









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author JSP useBean question
tomk4567@nowhere.net

2005-08-19, 4:17 pm

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>
cld71

2005-09-03, 6:56 pm

tomk4567@nowhere.net wrote:
> 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.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com