您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > 实验五使用Struts快速实现Web开发
实验报告实验课程名称:JavaEE程序设计与应用开发本次实验是第次,名称为:使用Struts快速实现Web开发学生姓名:班级学号学院(系):指导教师:成绩:实验五使用Struts快速实现Web开发一、实验目的MVC架构Struts为Web开发遵循MVC设计模式提供了高效的开发环境。现在被开发者广泛使用,成了事实上的开发标准。通过本实验掌握在Eclipse下开发Struts的方法和过程,深入理解Struts架构思想。二、实验内容完成一个企业挑选学生的案例:display.jsp页面上用表格显示学生的学号,姓名,性别,出生年月,家庭住址在每个学生后面还有一个挑选链接,点击,能将该学生挑选到公司的后备名单中cart.jsp显示被挑选的学生的详细资料,每个学生后面也有一个链接:取消挑选功能:query;select;delete三、实验方法和步骤编写实验代码:程序结构:StudentDao.javapackagedao;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.util.ArrayList;importpo.*;//访问数据库publicclassStudentDao{privateConnectionconn=null;publicvoidinitConnection(){//初始化数据库try{Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);Connectionconn=DriverManager.getConnection(jdbc:odbc:DSSchool);}catch(Exceptionex){ex.printStackTrace();}}publicArrayListqueryStu(){ArrayListstus=newArrayList();Stringsql=SELECT学号,姓名,性别,出生年月,家庭住址FROM学籍;try{this.initConnection();ResultSetrs=conn.createStatement().executeQuery(sql);while(rs.next()){Studentstu=newStudent();stu.setStuId(rs.getString(学号));stu.setStuName(rs.getString(姓名));stu.setStuSex(rs.getString(性别));stu.setStuBir(rs.getString(出生年月));stu.setStuAdd(rs.getString(家庭住址));stus.add(stu);}}catch(Exceptionex){ex.printStackTrace();}finally{this.closeConnection();}returnstus;Student.javapackagepo;publicclassStudent{privateStringstuId;privateStringstuName;privateStringstuSex;privateStringstuBir;privateStringstuAdd;publicStringgetStuAdd(){returnstuAdd;}publicvoidsetStuAdd(StringstuAdd){this.stuAdd=stuAdd;}publicStringgetStuBir(){returnstuBir;}publicvoidsetStuBir(StringstuBir){this.stuBir=stuBir;}publicStringgetStuId(){returnstuId;}publicvoidsetStuId(StringstuId){this.stuId=stuId;}publicStringgetStuName(){returnstuName;}publicvoidsetStuName(StringstuName){this.stuName=stuName;}publicStringgetStuSex(){returnstuSex;}publicvoidsetStuSex(StringstuSex){this.stuSex=stuSex;}}DeleteAction.javapackageaction;importjava.util.ArrayList;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importjavax.servlet.http.HttpSession;importorg.apache.struts.action.Action;importorg.apache.struts.action.ActionForm;importorg.apache.struts.action.ActionForward;importorg.apache.struts.action.ActionMapping;publicclassDeleteActionextendsAction{publicActionForwardexecute(ActionMappingmapping,ActionFormform,HttpServletRequestrequest,HttpServletResponseresponse){Stringstr=request.getParameter(ID);intid=Integer.parseInt(str);HttpSessionsession=request.getSession();ArrayListcart=(ArrayList)session.getAttribute(cart);cart.remove(id);returnnewActionForward(/cart.jsp);}}QueryAction.javapackageaction;importjava.util.ArrayList;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importjavax.servlet.http.HttpSession;importorg.apache.struts.action.Action;importorg.apache.struts.action.ActionForm;importorg.apache.struts.action.ActionForward;importorg.apache.struts.action.ActionMapping;importdao.StudentDao;publicclassQueryActionextendsAction{publicActionForwardexecute(ActionMappingmapping,ActionFormform,HttpServletRequestrequest,HttpServletResponseresponse){HttpSessionsession=request.getSession();StudentDaostudentDao=newStudentDao();ArrayListstus=studentDao.queryStu();session.setAttribute(stus,stus);returnnewActionForward(/display.jsp);}}SelectAction.javapackageaction;importjava.util.ArrayList;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importjavax.servlet.http.HttpSession;importorg.apache.struts.action.Action;importorg.apache.struts.action.ActionForm;importorg.apache.struts.action.ActionForward;importorg.apache.struts.action.ActionMapping;publicclassSelectActionextendsAction{publicActionForwardexecute(ActionMappingmapping,ActionFormform,HttpServletRequestrequest,HttpServletResponseresponse){Stringstr=request.getParameter(ID);intid=Integer.parseInt(str);HttpSessionsession=request.getSession();ArrayListstus=(ArrayList)session.getAttribute(stus);Objectselectdobj=stus.get(id);ArrayListcart=(ArrayList)session.getAttribute(cart);if(cart==null){cart=newArrayList();session.setAttribute(cart,cart);}cart.add(selectdobj);returnnewActionForward(/display.jsp);}}cart.jsp%@pagelanguage=javaimport=java.util.*pageEncoding=gb2312%jsp:directive.pageimport=po.Student;/%@tagliburi==bean%%@tagliburi==html%%@tagliburi==logic%!DOCTYPEHTMLPUBLIC-//W3C//DTDHTML4.01Transitional//ENhtmlheadtitleMyJSP'queryForm.jsp'startingpage/title/headbodyhtml:linkpage=/display.jsp返回继续挑选/html:linkbr显示挑选的结果brtablebgcolor=#ff80fftrtd学号/tdtd姓名/tdtd性别/tdtd出生年月/tdtd家庭住址/tdtd是否删除/td/trlogic:iterateid=stuname=cartindexId=itrtdbean:writename=stuproperty=stuId//tdtdbean:writename=stuproperty=stuName//tdtdbean:writename=stuproperty=stuSex//tdtdbean:writename=stuproperty=stuBir//tdtdbean:writename=stuproperty=stuAdd/
本文标题:实验五使用Struts快速实现Web开发
链接地址:https://www.777doc.com/doc-6184523 .html