预览加载中,请您耐心等待几秒...
1/4
2/4
3/4
4/4

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

第5章实验与训练指导答案 1、编写一个JSP页面,该页面提供了一个表单,用户可以通过表单输入梯形的 上底、下底和高的值,并提交给本JSP页面,该JSP页面将计算梯形的面积 任务交给一个Bean完成。JSP页面使用getProperty动作标记显示梯形的面积。 ladder.jsp: <%@pagepageEncoding=%> <jsp:useBeanid=class=scope=/> <HTML><BODYbgcolor=yellow><Fontsize=3> <FORMaction=Method=> 输入梯形上底、下底和高: 上底:<Inputtype=textname=value=0> 下底:<Inputtype=textname=value=0> 高:<Inputtype=textname=value=0> <Inputtype=submitvalue=提交> </FORM> <jsp:setPropertyname=property=/> 输入梯形上底、下底和高: 上底:<jsp:getPropertyname=property=/>, 下底:<jsp:getPropertyname=property=/>, 高:<jsp:getPropertyname=property=/>. <BR>面积是:<jsp:getPropertyname=property=/> </FONT></BODY></HTML> Ladder.java: packagepfc; publicclassLadder { doubletop=0,bottom=0,height=0,area=-1; publicdoublegetArea() {area=(top+bottom)*height/2; returnarea; } publicdoublegetBottom(){ returnbottom; } publicvoidsetBottom(doublebottom){ this.bottom=bottom; } publicdoublegetHeight(){ returnheight; } publicvoidsetHeight(doubleheight){ this.height=height; } publicdoublegetTop(){ returntop; } publicvoidsetTop(doubletop){ this.top=top; } } 2、编写两个jsp页面a.jsp和b.jsp,a.jsp页面提供了一个表单,用户可以通过表 单输入矩形的两个边长提交给b.jsp页面,b.jsp调用一个bean去完成计算矩 形面积任务。b.jsp页面使用getProperty动作标记显示矩形面积。 a.jsp: <%@pagepageEncoding=%> <jsp:useBeanid=class=scope=/> <HTML><BODYbgcolor=yellow><Fontsize=3> <FORMaction=Method=> 输入矩形的长和宽: 长:<Inputtype=textname=value=0> 宽:<Inputtype=textname=value=0> <Inputtype=submitvalue=提交> </FORM> </FONT></BODY></HTML> b.jsp: <%@pagepageEncoding=%> <jsp:useBeanid=class=scope=/> <HTML><BODYbgcolor=yellow><Fontsize=3> <jsp:setPropertyname=property=/> 矩形的长和宽: 长:<jsp:getPropertyname=property=/>, 宽:<jsp:getPropertyname=property=/>, <BR>面积是:<jsp:getPropertyname=property=/> </FONT></BODY></HTML> Rectangle.java: packagepfc; publicclassRectangle { doublelongside=0,width=0,area=-1; publicdoublegetArea() {area=longside*width; returnarea; } publicdoublegetLongside(){ returnlongside; } publicvoidsetLongside(doublelongside){ this.longside=longside; } publicdoublegetWidth(){ returnwidth; } publicvoids