计算三角形面积的页面

来源:互联网 发布:左右删失数据 编辑:程序博客网 时间:2024/05/09 05:18

GetArea.tag

<%@ tag import="java.util.*" %><%@ attribute name="sideA" required="true" %><%@ attribute name="sideB" required="true" %><%@ attribute name="sideC" required="true" %><%@ variable name-given="area" variable-class="java.lang.Double"  scope="AT_END" %><%double a=Double.parseDouble(sideA);double b=Double.parseDouble(sideB);double c=Double.parseDouble(sideC);if(a+b>c&&a+c>b&&b+c>a){double p=(a+b+c)/2.0;double area0=Math.sqrt(p*(p-a)*(p-b)*(p-c));jspContext.setAttribute("area",new Double(area0));}else{jspContext.setAttribute("area",new Double(-1.0));}%>

one.jsp

<%@ page contentType="text/html; charset=GB2312" %><%@ page import="java.text.*" %><%@ taglib tagdir="/WEB-INF/tags/ch3" prefix="computer" %><HTML><BODY BGCOLOR=#F0F8FF><TITLE>one</TITLE><computer:GetArea sideA="3.1" sideB="4.2" sideC="5.3"/><%NumberFormat f=NumberFormat.getInstance();f.setMaximumFractionDigits(3);if(area!=-1){double s=area.doubleValue();String str=f.format(s);out.print("面积是:"+str);}else out.print("不能构成三角形");%></BODY></HTML>

two.jsp

<%@ page contentType="text/html; charset=GB2312" %><%@ page import="java.text.*" %><%@ taglib tagdir="/WEB-INF/tags/ch3" prefix="computer" %><HTML><BODY BGCOLOR=#F0F8FF><TITLE>one</TITLE><computer:GetArea sideA="3.1" sideB="4.2" sideC="5.3"/><%NumberFormat f=NumberFormat.getInstance();f.setMaximumFractionDigits(6);if(area!=-1){double s=area.doubleValue();String str=f.format(s);out.print("面积是:"+str);}else out.print("不能构成三角形");%></BODY></HTML>
0 0