西北师范大学计算机科学与工程学院学生实验报告学号:2013710201072015年10月15日系别计算机专业计算机科学与技术班级2013软件一班姓名高凯课程名称面向对象分析与设计课程类型专业必修学时数实验名称Struts2开发案例实验目的和要求:1.熟悉和认识Struts2开发案例。2.对Struts2开发案例进行详细分析实验内容:1.MVC模式MVC:Model-View-Controller2.Structs2工作原理2.1Container调用控制器(Struts2.1以前FilterDispatcher,以后为StrutsPrepareAndExecuteFilter.2Controller通过ActionMapper获得Action的信息.3Controller调用ActionProxy.4ActionProxy读取struts.xml文件获取action和interceptorstack的信息.5ActionProxy把request请求传递给ActionInvocation.6ActionInvocation依次调用action和interceptor.7根据action的配置信息,产生result.8Result信息返回给ActionInvocation.9产生一个HttpServletResponse响应.10产生的响应行为发送给客服端。3.Structs2设计登陆界面login.jsp%@pagelanguage=javacontentType=text/html;charset=GBKpageEncoding=GBK%%@taglibprefix=suri=/struts-tags%htmlheadmetahttp-equiv=Content-Typecontent=text/html;charset=GBKtitles:textname=loginPage//title/headbodys:formaction=logins:textfieldname=usernamekey=user/s:textfieldname=passwordkey=pass/s:submitkey=login//s:form/body/html登陆成功界面welcome.jsp%@pagelanguage=javacontentType=text/html;charset=GBKpageEncoding=GBK%%@taglibprefix=suri=/struts-tags%htmlheadtitles:textname=succPage//titlemetahttp-equiv=Content-Typecontent=text/html;charset=GBK/headbodys:textname=succTips:param${sessionScope.user}/s:param/s:textbr//body/html登陆失败界面error.jsp%@pagelanguage=javacontentType=text/html;charset=GBKpageEncoding=GBK%%@taglibprefix=suri=/struts-tags%htmlheadtitles:textname=errorPage//titlemetahttp-equiv=Content-Typecontent=text/html;charset=GBK/headbodys:textname=failTip//body/html登录界面:登陆成功登陆失败添加学生:%@pagecontentType=text/html;charset=UTF-8%%@taglibprefix=suri=/struts-tags%htmlheadtitleCustomerForm-Struts2Demo|ViralPatel.net/title/headbodyh2align=center----------AddStudent----------/h2tablealign=centerborder=1bordercolor=#3366cctrtd s:actionerror/s:formaction=studentmethod=postnamespace=/s:textfieldname=student.idkey=idsize=20/s:textfieldname=student.namekey=namesize=20/s:textfieldname=student.agekey=agesize=20/s:textfieldname=student.emailkey=emailsize=20/s:textfieldname=student.telephonekey=telephonesize=20/s:textfieldname=student.sexkey=sexsize=20/s:textfieldname=student.schoolkey=schoolsize=20/s:textfieldname=student.snumberkey=snumbersize=20/s:submitmethod=executekey=label.add.studentalign=center//s:form/td/tr/table/body/html查找学生:%@pagecontentType=text/html;charset=UTF-8%%@taglibprefix=suri=/struts-tags%htmlheadmetahttp-equiv=Content-Typecontent=text/html;charset=UTF-8titleFindUser/title/headbodyh2align=center----------FindStudent----------/h2tablealign=centerborder=1bordercolor=#3366cctrtd s:actionerror/s:formaction=find.actionmethod=postvalidate=trues:textfieldname=idkey=idsize=20/s:submitmethod=executekey=label.add.findalign=center//s:form/td/tr/table/body/html删除学生:%@pagecontentType=text/html;charset=UTF-8%%@taglibprefix=suri=/struts-tags%htmlheadtitleStudentForm-Struts2Demo|ViralPatel.net/title/headbodyh2align=center----------FindStudent----------/h2tablealign=centerborder=1bordercolor=#3366cctrtd s:actionerror/s:formaction=delete.actionmethod=postvalidate=trues:textfieldname=idkey=idsize=20/s:submitmethod=executekey=label.add.deletealign=center//s:form/td/tr/table/body/html更新学生信息:%@pagecontentType=text/html;charset=UTF-8%%@taglibprefix=suri=/struts-tags%htmlheadtitleStudentForm-Struts2Demo|ViralPatel.net/title/headbodyh2align=center----------UpdateStudent----------/h2tablealign=centerborder=1bordercolor=#3366cctrtd s:actionerror/s:formaction=update.actionmethod=postvalidate=trues:textfieldname=student.idkey=idsize=20/s:textfieldname=student.namekey=namesize=20/s:textfieldname=student.agekey=agesize=20/s:textfieldname=student.emailkey=emailsize=20/s:textfieldname=student.telephonekey=telephonesize=20/s:textfieldname=student.sexkey=sexsize=20/s:textfieldname=student.schoolkey=schoolsize=20/s:textfieldname=student.snumberkey=snumbersize=20/s:submitmethod=executekey=label.add.updatealign=center//s:form/td/tr/table/body/html实验总结:通过本实验学会了struts2的体系结构,Struts2以WebWork为核心,采用拦截器的机制来处理用户的请求,这样的设计也使得业务逻辑控制器能够与ServletAPI完全脱离开,所以Struts2可以理解为WebWork的更新产品。虽然从Struts1到Struts2有着太大的变化,但是相对于WebWork,Struts2的变化很小。成绩批阅教师批阅日期