使用JavaBean计算圆的周长与面积

创建名称为“radiusInput.jsp”的页面文件,该页面文件将实现提示用户输入圆半径的功能,主要代码如下: 

 

  1. <body>  
  2.      <form id="form1" name="form1" method="post" action="circle.jsp">  
  3.              请输入圆的半径:  
  4.              <input name="radius" type="text" id="radius" />  
  5.              <input type=“submit” name=“submit” value=“开始计算” />  
  6.      </form>  
  7. </body>   

创建名称为“circle.jsp”的页面文件,该页面文件将实现显示圆的面积和周长的计算结果,主要代码如下: 

  1. <body>  
  2.   <jsp:useBean id="circleBean" scope="session" class="circle.Circle"/></p>  
  3.   <%  
  4.     int radius=Integer.parseInt(request.getParameter("radius"));  
  5.     circleBean.setRadius(radius);  
  6.     out.println("圆的半径是:"+circleBean.getRadius());  
  7.     out.println("圆的周长是:"+circleBean.circleLength());  
  8.     out.println("圆的面积是:"+circleBean.circleArea());  
  9. %>  
  10. </body>   
posted @ 2017-11-07 12:38  为PG1打call  阅读(2774)  评论(0编辑  收藏  举报