总共分为三组代码 circle.jsp用于显示 Circle.java 用于定义类 radiusInput用于输入
circle.jsp如下
<%@ page language="java" import="circle.class" contentType="text/html;charset=GBK" pageEncoding="ISO-8859-1" session="True"%>
<jsp:useBean id="circleBean" scope="page" class="circle.Circle" type="java.lang.String" ></jsp:useBean></p>
<html>
<body>
<%
int radius=Integer.parseInt(request.getParameter("radius"));
circleBean.setRadius(radius);
out.println("圆的半径是:"+circleBean.getRadius());
out.println("圆的周长是:"+circleBean.getLength());
out.println("圆的面积是:"+circleBean.getArea());
%>
</body>
</html>
我用的是Tomcat6.0
已经把circle.class类放在了C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\ROOT\WEB-INF\classes下
运行错误:
org.apache.jasper.JasperException: /circle.jsp(2,0) The value for the useBean class attribute circle.Circle is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1272)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1178)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
.........
java程序如下:
package circle;
public class Circle{
private int radius=1;
public Circle(){}
public int getRadius(){
return radius;
}
public void setRadius(int rRadius){
radius=rRadius;
}
public double circleLength(){
return Math.PI*radius*2.0;
}
public double circleArea(){
return Math.PI*radius*radius;
}
}
radiusInput的jsp页面可以正确运行 代码我略去了。。。
输入半径的代码我也发了吧:
<body>
<form id="form1" name="form1" method="post" action="circle.jsp">
请输入圆的半径:
<input name="radius" type="text" id="radius"/>
<input type="submit" name="submit" value="开始计算"/>
</form>
</body>
收到一只叮咚
慕神8447489
相关分类