a.jsp如下:
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
a.jsp b.jsp如下
<%@ page language="java" import="java.util.*" pageEncoding="gb2312" import="java.lang.*;"%>
b.jsp <%
double length=Double.valueOf(request.getParameter("length"));
double width=Double.valueOf(request.getParameter("width"));
%>
<%!double area; %>
<%
ab.setLength(length);
ab.setWidth(width);
area=ab.computeArea();
%>
矩形的面积是: <%
out.println(area);
%>
报名为mypackage里面放的类为:Compute代码如下:
package mypackage;
public class Compute {
private double length;
private double width;
public double getLength() {
return length;
}
public void setLength(double length) {
this.length = length;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double computeArea()
{
return this.length*this.width;
}
}