• JSP 第三周作业


    main.jsp代码

    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
    <%@ include file="circle.jsp" %>
    
    <%@ include file="ladder.jsp" %> 
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
      </head>
      
      <body>
      
      </body>
    </html>

    circle.jsp代码

    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
      </head>
      
      <body>
        <div>
            <form action="main.jsp">
                    请输入半径:<input type="text"  name="R" > <br>
             <input type="submit" value="计算"> <br>
            </form>
        </div>
        <%
            String R=request.getParameter("R");
            if(R!=null){
                double PI=3.14;
                double r=Double.parseDouble(R);
                double area=r*r*3.14;
                out.print("圆的面积为"+area);
                request.setAttribute("r", r);
                request.setAttribute("area", area);
            }
            
        %>
      </body>
    </html>

    ladder.jsp代码

    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
      </head>
      
      <body>
        <div>
            <form action="main.jsp">
           请输入梯形上底: <input type="text" name="a"> <br>
           请输入梯形下底: <input type="text" name="b" > <br>
           请输入梯形的高: <input type="text" name="h"> <br>
             <input type="submit" value="计算"> <br><br>
             </form>
         </div>
              <%
            String a=request.getParameter("a");
            String b=request.getParameter("b");
            String h=request.getParameter("h");
            if(a!=null&&b!=null&&h!=null){
                double A=Double.parseDouble(a);
                double B=Double.parseDouble(b);
                double H=Double.parseDouble(h);
                double M=(A+B)*H/2;
                out.println("梯形面积"+M);
                request.setAttribute("A", a);
                request.setAttribute("B", b);
                request.setAttribute("H", h);
                request.setAttribute("M", M);
            }
        %>
      </body>
    </html>

    运行图片

    1).圆形

    2).梯形

  • 相关阅读:
    数据库_初学
    数据库—修改表的列
    做一个导航栏(bootstrap)
    几个比较常用的特效
    当、你想给一个目标挂上一个事件时
    图片轮播的几个小程序
    JS练习题 ( 下拉菜单;好友选中输入)
    Bootstrap 按钮和折叠插件
    Bootstrap 轮播插件
    Bootstrap 弹出框和警告框插件
  • 原文地址:https://www.cnblogs.com/lixiaoai/p/12559249.html
Copyright © 2020-2023  润新知