JAVA 类型
package mypackge;
public class Student {
int r;
double area;
double zc;
public double getZc() {
return 3.14*r*2;
}
public void setZc(double zc) {
this.zc = zc;
}
public int getR() {
return r;
}
public void setR(int r) {
this.r = r;
}
public double getArea() {
return 3.14*r*r;
}
public void setArea(double area) {
this.area = area;
}
}
JSP文件类型
<%@ page language="java" contentType="text/html; charset=gb2312"
import="mypackge.*"%>
<jsp:useBean class="mypackge.Student" id="s1" scope="session"></jsp:useBean>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "" target="_blank">http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Insert title here</title>
</head>
<body>
<jsp:setProperty property="r" name="s1" />
<%
s1.setR(5);
out.println("这个半径为5的圆的面积是"+s1.getArea()+"<br>");
out.println("这个半径为5的圆的周长是"+s1.getZc()+"<br>");
%>
</body>
</html>