Javabean实现求圆的面积方法二
r2.jsp页面略
circle2.jsp
<jsp:useBean id="circle" class="com.bean.NewCircle" scope="page"/> <% double r=Double.parseDouble(request.getParameter("r")); circle.setR(r); %> <BR>圆的面积:<%=circle.getCircleArea() %> <jsp:getProperty name="circle" property="circleArea"/>
三、servlet实现求圆的面积
以下部分内容隐藏,请发表评论后查看!
r4.jsp
<form action="servletR" Method="post" > 输入圆的半径:<Input type=text name="r"> <Input type=submit value="提交"> </form>
servletR.java
package com.servlet; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class servletR extends HttpServlet { public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); out.println("<HTML>"); out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>"); out.println(" <BODY>"); try { double r=Double.parseDouble(request.getParameter("r")); double circleArea=Math.PI*r*r; out.println("<BR>圆的面积是:"+circleArea); } catch(NumberFormatException e) { out.println("<BR>请输入数字字符"); } out.println(" </BODY>"); out.println("</HTML>"); out.flush(); out.close();} }
web.xml
<servlet> <servlet-name>servletR</servlet-name> <servlet-class>com.servlet.servletR</servlet-class> </servlet> <servlet-mapping> <servlet-name>servletR</servlet-name> <url-pattern>/servletR</url-pattern> </servlet-mapping>
永哥通过一个简单案例(求圆的面积)分别使用Jsp、javabean、Servlet三种方法来实现,让你深入理解Jsp、javabean、Servlet,并学会它们的使用,下一节课,仍然通过这个案例,教大家综合使用jsp+javabean+servlet实现求圆的面积。
125jz网原创文章。发布者:江山如画,转载请注明出处:http://www.125jz.com/1388.html
评论列表(2条)
强,学习下
牛( ఠൠఠ )ノ