急救,哪位有实力,有魄力的大哥帮帮俺,感觉都正确,为何总是出错呀!
我的文件名为Circle.class的类源码:
package testclass;
import java.io.*;
public class Circle
{ int r;
double areas;
double lengths;
public void Circle()
{ r=1;
}
public int getr()
{return r;
}
public void setr(int newr)
{r=newr;
}
public double getareas()
{ return areas=Math.PI*r*r;
}
public double getlengths()
{return lengths=2*Math.PI*r;
}
}
下面是一个通过USEBEAN调用数据的JSP页面:circle.jsp 代码如下:
<%@ page contentType="text/html;charset=GB2312" %>
<HTML>
<BODY bgcolor=#9999CC><Font size=5>
<%@ page import="testclass.Circle"%>
<jsp:useBean id="girl" class="testclass.Circle" scope="page" >
</jsp:useBean>
<% //设置圆的半径:
girl.setr(400);
%>
<P>圆的半径是:
<%=girl.getr()%>
<P>圆的面积是:
<%=girl.getareas()%>
<P>圆的周长是:
<%=girl.getlengths()%>
</BODY>
</HTML>
我通过上面这个页面显示数据能够成功,但为何我通过getproperty显示数据时总是报错:操作在一个空的对象上,请帮忙,在此感谢!
下面是出错页面circle2.jsp的相关代码:
<%@ page contentType="text/html;charset=GB2312" %>
<HTML>
<BODY bgcolor=#9999CC><Font size=5>
<%@ page import="testclass.Circle"%>
<jsp:useBean id="girl" class="testclass.Circle" scope="page" >
</jsp:useBean>
<% //设置圆的半径:
girl.setr(400);
%>
<P>圆的半径是:
<jsp:getProperty name= "girl" property= "r" />
<P>圆的面积是:
<jsp:getProperty name= "girl" property= "areas" />
<P>圆的周长是:
<jsp:getProperty name= "girl" property= "lengths" />
</BODY>
</HTML>
org.apache.jasper.JasperException: Attempted a bean operation on a null object.
org.apache.jasper.runtime.JspRuntimeLibrary.handleGetProperty(JspRuntimeLibrary.java:647)
org.apache.jsp.circle2_jsp._jspService(circle2_jsp.java:62)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
[此贴子已经被作者于2005-12-26 11:13:26编辑过]