利用Servlet和JSP设计并实现简单的图书管理系统

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

实验六利用Servlet和JSP设计并实现简单的图书管理系统1、实验目的1)掌握对JDBC基本操作步骤的简单封装2)掌握Servlet和JSP结合使用3)掌握MVC设计模式4)掌握监听器、过滤器的使用2、实验设备与环境硬件:安装有WindowsXP系统的微机一台。软件:JDK1.6、MyEclipse6.0以上、Oracle或者SQLServer2000(2005、2008)和Tomcat6。3、实验内容设计一个通用的基于浏览器/服务器的简单的图书管理系统。系统包括用户登录、图书基本信息维护(图书的增删改查)等简单功能。4、实验要求1)用户、图书的基本信息采用数据库存放2)使用Servlet作为业务流程控制器3)使用session、JavaBean进行数据传递5、实验要求1)实验前充分预习实验指导书内容及相关理论知识内容;实验时提交本次实验的预习报告。2)实验中严格遵守实验室规范和制度,调试程序出现的问题并给出解决方法。认真完成实验内容并做好实验纪录3)实验后必须按照要求独立完成实验报告4)打印的源程序清单和测试结果附在实验报告的后面。源程序必须有注释以及必要的测试数据和运行结果数据6、实验程序1登录界面packagecom.imut.servlet;importjava.io.IOException;importjavax.servlet.ServletException;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importjavax.servlet.http.HttpSession;importcom.imut.javabean.User;importcom.imut.javabean.UserDBAccess;publicclassLoginServletextendsHttpServlet{publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{doPost(request,response);}publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{HttpSessionsession=request.getSession();request.setCharacterEncoding(UTF-8);response.setCharacterEncoding(UTF-8);Stringname=request.getParameter(name);Stringpasswd=request.getParameter(password);UserDBAccessdbAccess=newUserDBAccess();Useruser=dbAccess.login(name,passwd);if(user!=null){session.setAttribute(user,user);response.sendRedirect();}else{session.setAttribute(message,登录信息有误,请重新登录!!!);response.sendRedirect();}}}2添加packagecom.imut.servlet;importjava.io.IOException;importjava.util.Date;importjava.util.List;importjavax.servlet.ServletException;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importjavax.servlet.http.HttpSession;importcom.imut.javabean.Book;importcom.imut.javabean.BookDBAccess;importcom.imut.javabean.User;importcom.imut.javabean.UserDBAccess;publicclassAddBookServletextendsHttpServlet{publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{doPost(request,response);}publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{HttpSessionsession=request.getSession();request.setCharacterEncoding(UTF-8);response.setCharacterEncoding(UTF-8);StringbookName=request.getParameter(bookName);StringISBN=request.getParameter(ISBN);Stringauthor=request.getParameter(author);StringpublishCom=request.getParameter(publishCom);StringstrPrice=request.getParameter(price);StringpublishDate=request.getParameter(publishDate);Stringremark=request.getParameter(remark);floatprice=Float.parseFloat(strPrice);BookDBAccessdbAccess=newBookDBAccess();Bookbook=newBook(dbAccess.getBookId(),bookName,ISBN,author,publishCom,price,publishDate,remark);dbAccess.addBook(book);session.setAttribute(message,图书信息添加成功!);request.getRequestDispatcher(/listAllBookServlet).forward(request,response);}}3删除packagecom.imut.servlet;importjava.io.IOException;importjava.util.List;importjavax.servlet.ServletException;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importjavax.servlet.http.HttpSession;importcom.imut.javabean.Book;importcom.imut.javabean.BookDBAccess;importcom.imut.javabean.User;importcom.imut.javabean.UserDBAccess;publicclassDeleteBookServletextendsHttpServlet{publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{doPost(request,response);}publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{HttpSessionsession=request.getSession();request.setCharacterEncoding(UTF-8);response.setCharacterEncoding(UTF-8);Stringid=request.getParameter(bookId);intbookId=Integer.parseInt(id);BookDBAccessdbAccess=newBookDBAccess();dbAccess.delBookById(bookId);session.setAttribute(message,删除图书信息成功!);request.getRequestDispatcher(/listAllBookServlet).forward(request,response);}}4更新packagecom.imut.servlet;importjava.io.IOException;importjava.util.List;importjavax.servlet.ServletException;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importjavax.servlet.http.HttpSession;importcom.imut.javabean.Book;importcom.imut.javabean.BookDBAccess;importcom.imut.javabean.User;importcom.imut.javabean.UserDBAccess;publicclassUpdateBookServletextendsHttpServlet{publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{doPost(request,response);}publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{HttpSessionsession=request.getSession();request.setCharacterEncoding(UTF-8);response.setCharacterEncoding(UTF-8);Stringid=request.getParameter(bookId);StringbookName=request.getParameter(bookName);S

1 / 22
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功