jsp页面中用include动作标记加载相应页面计算圆的面积和梯形的面积?
发布网友
发布时间:2022-04-30 21:43
我来回答
共1个回答
热心网友
时间:2023-10-03 03:38
<%@ page contentType="text/html; charset=gb2312" language="java"
errorPage=""%>
<html>
<head>
<title>无标题文档</title>
</head>
<body bgcolor="">
<%
double PI = 3.1415, r = 3, a = 5, b = 10, h = 6;
%>
<br>
<!-- 计算半径<%=r%>圆的面积,以及上底<%=a%>,下底<%=b%>,高为<%=h%>梯形的面积:-->
<jsp:include page="mianji.jsp">
<jsp:param name="yuanPI" value="<%=PI%>"></jsp:param>
<jsp:param name="banjing" value="<%=r%>"></jsp:param>
<jsp:param name="tixinga" value="<%=a%>"></jsp:param>
<jsp:param name="tixingb" value="<%=b%>"></jsp:param>
<jsp:param name="tixingh" value="<%=h%>"></jsp:param>
</jsp:include>
</body>
</html>
<%@ page contentType="text/html; charset=gb2312" language="java"
errorPage=""%>
<%!public String getArea(double a, double b, double h) {
double area = (a + b) * h / 2.0;
return "" + area;
}%>
<%!public String getCArea(double PI , double r) {
double Carea=PI*r*r;
return "" + Carea;
}%>
<html>
<head>
<title>无标题文档</title>
</head>
<body>
<%String banjing=request.getParameter("banjing");
String yuanPI=request.getParameter("yuanPI");
String tixinga = request.getParameter("tixinga");
String tixingb = request.getParameter("tixingb");
String tixingh = request.getParameter("tixingh");
double a = Double.parseDouble(tixinga);
double b = Double.parseDouble(tixingb);
double h = Double.parseDouble(tixingh);
double PI=Double.parseDouble(yuanPI);
double r=Double.parseDouble(banjing);
%>
<br>
梯形的面积为:<%=getArea(a, b, h)%>
园的面积为:<%=getCArea(PI,r)%></body>
</html>
帮你整理了下