"JSP practice" to determine whether a triangle can be formed and calculate the area of a given triangle

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.