Test.java
PackagePackage1; Public classTest {DoubleSide1 =-1, Side2 =-1, side3 =-1, area = 1; Booleantriangle; Public DoubleGetSide1 () {returnSide1; } Public voidSetSide1 (Doubleside1) { This. Side1 =Side1; } Public DoubleGetSide2 () {returnSide2; } Public voidSetSide2 (DoubleSide2) { This. Side2 =Side2; } Public DoubleGetSide3 () {returnSide3; } Public voidSetSide3 (Doubleside3) { This. Side3 =Side3; } Public DoubleGetarea () {Doublep = (side1 + side2 + side3)/2.0; if(triangle) area = MATH.SQRT (P * (p-side1) * (P-SIDE2) * (P-side3)); returnArea ; } Public voidSetarea (DoubleArea ) { This. Area =Area ; } Public BooleanIstriangle () {if(Side1<side2+side3 && side2<side1+side3 && side3<side1+side2) Triangle=true; Elsetriangle=false; returntriangle; } Public voidSettriangle (Booleantriangle) { This. Triangle =triangle; } }
triangle.jsp
<% @pageContentType= "text/html;charset=gb2312"pageencoding= "gb2312" %><% @pageImport= "Package1." Test " %><Jsp:usebeanID= "tri"class= "Package1." Test "Scope= "page" /><HTML> <Head></Head> <Body> <formAction=""Method= "POST">A:<inputtype= "text"name= "Side1"value= "0" />B:<inputtype= "text"name= "Side2"value= "0" />C:<inputtype= "text"name= "Side3"value= "0" /> <inputtype= "Submit"value= "Submit" /> </form> <Jsp:setpropertyname= "tri" Property="*" />the three sides of the triangle are: Side A:<Jsp:getpropertyname= "tri" Property= "Side1" />Side B:<Jsp:getpropertyname= "tri" Property= "Side2" />side c:<Jsp:getpropertyname= "tri" Property= "Side3" /> <BR/>whether the triangle can be formed:<Jsp:getpropertyname= "tri" Property= "Triangle" /> <!--If you do not first determine whether it is triangle, the servlet class to obtain an area of the triangle judgment is false, the output value is always 1 -the area is:<Jsp:getpropertyname= "tri" Property= "area" /> </Body></HTML>
"JSP practice" to determine whether a triangle can be formed and calculate the area of a given triangle