1、MVC综合设计昆明理工大学信息工程与自动化学院学生实验报告( 2012 2013 学年 第 一 学期 )课程名称:JAVA EE技术 开课实验室:信自楼444 2012 年 12 月 25 日年级、专业、班计科10级学号201010803116姓名李力成绩实验项目名称实验四 MVC综合设计指导教师杨云飞教师评语 教师签名: 年 月 日一、实验目的通过上机,熟练掌握5层MVC设计模式。二、内容及要求上机内容:用5层MVC分层模式完成用户管理的功能。具有增加、删除、更新、显示、查询等功能。三、步骤及具体实施1、简要描述程序的开发流程、文件部署截图、及各种配置;开发流程:文件部署:数据库:2、程序代
2、码Com.city.oa.action中EmployeeMainAction:package com.city.oa.action;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import com.city.oa.business.IEmployee;im
3、port com.city.oa.factory.BussinessFactory;public class EmployeeAddAction extends HttpServlet private static final long serialVersionUID = 1L; public EmployeeAddAction() super(); public void destroy() super.destroy(); / Just puts destroy string in log / Put your code here public void doGet(HttpServle
4、tRequest request, HttpServletResponse response) throws ServletException, IOException doPost(request,response); public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException request.setCharacterEncoding(gb2312); String id=request.getParameter(empid)
5、; String name=request.getParameter(name); String password=request.getParameter(password); String ageStr=request.getParameter(age); int age=Integer.parseInt(ageStr); IEmployee emp=BussinessFactory.getEmployee(); try emp.add(id, name, password, age); catch(Exception e) System.out.println(modify Employ
6、ee error:+e.getMessage(); response.sendRedirect(employee/main.do); public void init() throws ServletException / Put your code here Com.city.oa.action中EmployeeDeletAction.java:package com.city.oa.action;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.http.HttpSer
7、vlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import com.city.oa.business.*;import com.city.oa.factory.*;public class EmployeeDeletAction extends HttpServlet /* * */ private static final long serialVersionUID = 1L; /* * Constructor of the object. */
8、public EmployeeDeletAction() super(); /* * Destruction of the servlet. */ public void destroy() super.destroy(); / Just puts destroy string in log / Put your code here /* * The doGet method of the servlet. * * This method is called when a form has its tag value method equals to get. * * param reques
9、t the request send by the client to the server * param response the response send by the server to the client * throws ServletException if an error occurred * throws IOException if an error occurred */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletExceptio
10、n, IOException doPost(request,response); /* * The doPost method of the servlet. * * This method is called when a form has its tag value method equals to post. * * param request the request send by the client to the server * param response the response send by the server to the client * throws Servle
11、tException if an error occurred * throws IOException if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException String userid=request.getParameter(userid); IEmployee emp=BussinessFactory.getEmployee(); try emp.delete(user
12、id); catch(Exception e) System.out.println(DeletEmployee error:+e.getMessage(); response.sendRedirect(main.do); /* * Initialization of the servlet. * * throws ServletException if an error occurs */ public void init() throws ServletException / Put your code here GetIdModify.java:package com.city.oa.a
13、ction;import java.io.IOException;import javax.servlet.RequestDispatcher;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import com.city.oa.business.*;import com.city.oa.factory.*;im
14、port com.city.oa.value.*;public class EmployeeGetIdModify extends HttpServlet public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException doPost(request,response); public void doPost(HttpServletRequest request, HttpServletResponse response) throws
15、 ServletException, IOException String id=request.getParameter(empid); IEmployee emp=BussinessFactory.getEmployee(); try EmployeeValue getEmpById=emp.getEmployee(id); request.setAttribute(getEmpById, getEmpById); RequestDispatcher rd=request.getRequestDispatcher(Modify.jsp); rd.forward(request,respon
16、se); catch(Exception e) System.out.println(forward values to modify error:+e.getMessage(); public void init() throws ServletException / Put your code here LoginActionAction.java:package com.city.oa.action;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.http.Http
17、Servlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import com.city.oa.business.*;import com.city.oa.factory.*;SuppressWarnings(serial)public class EmployeeLoginAction extends HttpServlet public void doGet(HttpServl
18、etRequest request, HttpServletResponse response) throws ServletException, IOException doPost(request,response); public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException String empid=request.getParameter(empid); String password=request.getParam
19、eter(password); boolean check=false; IEmployee emp=BussinessFactory.getEmployee(); try check=emp.check(empid, password); if(check=true) HttpSession session=request.getSession(true); session.setAttribute(empid, empid); catch(Exception e) System.out.println(login error:+e.getMessage(); System.out.prin
20、tln(you have login success); System.out.println(empid +empid); response.sendRedirect(employee/main.do); EmployeeModifyAction.java:package com.city.oa.action;import java.io.IOException;import java.util.*;import com.city.oa.business.*;import com.city.oa.factory.*;import com.city.oa.value.EmployeeValue
21、;import javax.servlet.RequestDispatcher;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;SuppressWarnings(serial)public class EmployeeMainAction
22、 extends HttpServlet /* * Constructor of the object. */ public EmployeeMainAction() super(); /* * Destruction of the servlet. */ public void destroy() super.destroy(); / Just puts destroy string in log / Put your code here public void doGet(HttpServletRequest request, HttpServletResponse response) t
23、hrows ServletException, IOException /新加的; int countperpage=5; HttpSession session=request.getSession(); String pageIndex=request.getParameter(pageIndex); if(pageIndex=null) pageIndex=1; /原来的; try IEmployee emp=BussinessFactory.getEmployee(); List empList=emp.getlist(); request.setAttribute(empList,e
24、mpList); /新加的; int pageCount; if(empList.size()%countperpage=0) pageCount=empList.size()/countperpage; else pageCount=empList.size()/countperpage+1; session.setAttribute(pageCount, pageCount); session.setAttribute(empListCount, empList.size(); /根据当前页数在查询集合中获取数据 int currentPageIndex=Integer.parseInt(
25、pageIndex); ArrayList pageempList=new ArrayList(); for(int i=0;i=(currentPageIndex-1)*countperpage&i(currentPageIndex)*countperpage) pageempList.add(empList.get(i); System.out.println(i +i); session.setAttribute(pageempList, pageempList); session.setAttribute(currentPageIndex, currentPageIndex); /原来
26、代码; RequestDispatcher rd=request.getRequestDispatcher(main.jsp); rd.forward(request, response); System.out.println(currentPageIndex +currentPageIndex); System.out.println(pageempList +pageempList); System.out.println(pageCount +pageCount); catch(Exception e) String mess=e.getMessage(); response.send
27、Redirect(./error.jsp?mess=+mess); public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException doGet(request,response); public void init() throws ServletException / Put your code here Com.city.oa.bussiness中IEmployee.javapackage com.city.oa.busines
28、s;import java.util.List;import com.city.oa.value.*;public interface IEmployee /增加员工 public void add(String userid,String name,String password, int age)throws Exception; /修改员工 public void modify(String userid,String name,String password, int age)throws Exception; /删除员工 public void delete(String userid)throws Exception; /取得所有员工列表 public List getlist()throws Exception; /取得一个员工 public EmployeeValue getEmployee(String userid)throws Exception; /验证密码 p
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1