编写两个jsp页面a.jsp、b.jsp及一个javabeanCompute.java,a.asp页面提供一个表单,

2025-01-05 10:38:14
推荐回答(1个)
回答1:

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;
}
}