设计一个页面,用户在上面输入圆的半径,提交后显示出圆的周长和面积,要求使用JavaBean类

//Circle.java
package beans;

public class Circle {
    private double radius;
    private double zhouchang;
    private double area;
    public double getRadius() {
        return radius;
    }
    public void setRadius(double radius) {
        this.radius = radius;
    }
    public double getZhouchang() {
        return 2*Math.PI*radius;
    }
    public void setZhouchang(double zhouchang) {
        this.zhouchang = zhouchang;
    }
    public double getArea() {
        return Math.PI*radius*radius;
    }
    public void setArea(double area) {
        this.area = area;
    }

}
//input.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<form  action="show.jsp" method="post">
<h3>请输入圆的半径:</h3>
    <table>
        <tr><td align="right">半径:</td>
            <td><input name="radius"></td>
        </tr>        
        <tr><td></td>
            <td><input type="submit" value="提交"></td>
        </tr>
    </table>
</form>
//show.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
  <head>   
    <title>利用JavaBean+JSP求圆的周长和面积</title>
  </head>
  
  <body>
    <jsp:useBean id="a" class="beans.Circle" scope="request"/>
    <jsp:setProperty name="a" property="*"/>
    <h3>调用jsp:getProperty作标签显示结果:</h3><br>
    <h5>
        圆的周长:
        <jsp:getProperty name="a" property="zhouchang"/><br>
        圆的面积:
        <jsp:getProperty name="a" property="area"/>
    </h5>
  </body>
</html>

 

posted on 2017-10-29 21:34  小星_log  阅读(2204)  评论(0编辑  收藏  举报