useBean 错误
<%@ page contentType= "text/html;charset=GB2312 " %>
<%@ page import= "Circle "%>
<HTML>
<BODY bgcolor=cyan> <Font size=1>
<jsp:useBean id= "girl " class= "Circle.class " scope= "page "/>
<%--通过上述JSP标签,客户获得了一个作用域是page,名字是girl的beans --%>
<% //设置圆的半径:
girl.setRadius(100);
%>
<P> 圆的半径是:
<%=girl.getRadius()%>
<P> 圆的周长是:
<%=girl.circlLength()%>
<P> 圆的面积是:
<%=girl.circleArea()%>
</BODY>
</HTML>
Circle.java
import java.io.*;
public class Circle
{ int radius;
public Circle()
{ radius=1;
}
public int getRadius()
{ return radius;
}
public void setRadius(int newRadius)
{radius=newRadius;
}
public double circleArea()
{return Math.PI*radius*radius;
}
public double circlLength()
{return 2.0*Math.PI*radius;
}
}
编译已通过;
错误:
org.apache.jasper.JasperException: Unable to compile class for JSP
Generated servlet error:
C:\Program Files\Apache Group\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\useBean_jsp.java:6: '. ' expected
import Circle;
^
1 error
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:332)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:412)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
我刚学JSP,许多东西都不懂,请各位大虾指教。
------解决方案--------------------JAVABEAN要放在一个包中的,你试一下
------解决方案--------------------bean 好像应该加包名的吧
------解决方案-------------------- <jsp:useBean id= "girl " class= "Circle.class " scope= "page "/>
这个应该是实例化一个class属性指定的类,其中class=包名.类名