1. 程式人生 > >計算三角形面積的頁面

計算三角形面積的頁面

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>