Javaweb学习总结(六):使用JavaBean计算圆的周长与面积

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

<body>
     <form id="form1" name="form1" method="post" action="circle.jsp">
             请输入圆的半径:
             <input name="radius" type="text" id="radius" />
             <input type=“submit” name=“submit” value=“开始计算” />
     </form>
</body> 
创建名称为“circle.jsp”的页面文件,该页面文件将实现显示圆的面积和周长的计算结果,主要代码如下: 

<body>
  <jsp:useBean id="circleBean" scope="session" class="circle.Circle"/></p>
  <%
  	int radius=Integer.parseInt(request.getParameter("radius"));
	circleBean.setRadius(radius);
	out.println("圆的半径是:"+circleBean.getRadius());
	out.println("圆的周长是:"+circleBean.circleLength());
	out.println("圆的面积是:"+circleBean.circleArea());
%>
</body> 

运行程序:

radiusInput.jsp



输入“50”单击“开始计算circle.jsp


你可能感兴趣的:(Javaweb学习总结(六):使用JavaBean计算圆的周长与面积)