资源描述
javaWeb图书管理系统
45
2020年4月19日
文档仅供参考
实验报告模板
实 验 报 告
课程名称 高级Java程序设计
实验项目 基于MVC模式的Web 综合应用
实验仪器 ____ 个人计算机 __
系 别___计算机学院 ___
专 业__计算机科学与技术_____
班级/学号____计科1204
学生姓名 ____
实验日期 _ /5/21-6/5_________
成 绩 _______________________
指导教师 _____ _________
目 录
第一章 需求分析
第二章 总体设计
2.1本系统的主要功能
2.2 Java源文件及其功能
2.3 项目构建思路
第三章 模块功能介绍
第四章 功能测试及运行效果
参考文献
工作总结
第一章:需求分析
任务1 开发图书馆管理信息系统
项目需求:
1. 基于MVC模式开发该Java Web项目;
2. 本系统有两类用户角色,普通用户和管理员用户;
3. 普通用户:浏览图书信息,分类浏览,能够分别根据书名、作者、出版社为关键字查询图书;登陆后还可借阅图书;
4. 管理员用户管理系统各项信息,包括:信息的添加、修改和删除。
5. 建立的图书类包含如下信息:编号、书名、作者、出版社、出版日期。
项目设计
n 选择开发模型——MVC
第二章:总体设计
2.1本系统的主要功能:
1、基于MVC模式开发该Java Web项目;
2、本系统有两类用户角色,普通用户和管理员用户;
3、普通用户:浏览图书信息,分类浏览,能够分别根据书名、作者、出版社为关键字查询图书;登陆后还可借阅图书;
4、管理员用户管理系统各项信息,包括:信息的添加、修改和删除。
5、建立的图书类包含如下信息:编号、书名、作者、出版社、出版日期。
2.2 Java源文件及其功能(功能在下一章讲述):
Index.jsp
<%-- Created by IntelliJ IDEA. --%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title></title>
</head>
<body>
<center>
<h2>欢迎进入图书馆里系统!</h2><p>
<form method="post" action="/servlets/depend.do">
普通用户<input type="radio" name="person" value="reader" checked><br>
管理员用户<input type="radio" name="person" value="editer"><br>
管理员密码<input type="password" name="password"><p>
<input type="submit" value="登录">
</form>
</center>
</body>
</html>
Manager.jsp
<%--
Created by IntelliJ IDEA.
User: Administrator
Date: 14-5-31
Time: 下午3:59
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" import="java.util.ArrayList,bean.bookinfo" %>
<html>
<head>
<title></title>
</head>
<body>
<center>
<h2><a href="/add.jsp">添加图书</a></h2>
<table align="center" border="1" >
<tr>
<font size="2" face="黑体" color="blue">
<th>编号</th><th>书名</th><th>作者</th><th>出版社</th><th>出版日期</th><th colspan="2">管理</th>
</font>
</tr>
<%
request.setCharacterEncoding("utf-8");
ArrayList<bookinfo> list=(ArrayList<bookinfo>)request.getAttribute("list");
for(bookinfo bi:list){
String id=bi.getId();
%>
<tr>
<td><%= bi.getId()%></td><td><%= bi.getName()%></td><td><%= bi.getAuthor()%></td><td><%= bi.getPress()%></td><td><%= bi.getDate()%></td>
<td><a href="/servlets/edit.do?id=<%= id%>">修改</a></td>
<td><a href="/servlets/delete.do?id=<%= id%>">删除</a></td>
</tr>
<%
}
%>
</table>
</center>
</body>
</html>
Reader.jsp
<%--
Created by IntelliJ IDEA.
User: Administrator
Date: 14-5-31
Time: 下午3:59
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" import="java.util.ArrayList,bean.bookinfo" %>
<html>
<head>
<title></title>
</head>
<body>
<center>
<form action="/servlets/borrow.do" method="post">
<table align="center" border="1" >
<caption><h2>现有图书信息</h2></caption><p>
<tr><td colspan="6" align="right"><a href="/check.jsp">点击查询</a></td></tr>
<tr>
<font size="2" face="黑体" color="blue"> <th>编号</th><th>书名</th><th>作者</th><th>出版社</th><th>出版日期</th><th colspan="2">借阅</th></font>
</tr>
<%
request.setCharacterEncoding("utf-8");
ArrayList<bookinfo> list=(ArrayList<bookinfo>)request.getAttribute("list");
for(bookinfo bi:list){
String id=bi.getId();
%>
<tr>
<td><%= bi.getId()%></td><td><%= bi.getName()%></td><td><%= bi.getAuthor()%></td><td><%= bi.getPress()%></td><td><%= bi.getDate()%></td>
<td><input type="radio" name="borrow" value="123"></td>
<input type="hidden" name="id" value="<%= bi.getId()%>">
</tr>
<%
}
%>
</table><p>
<input type="submit" value="提交">
</form>
</center>
</body>
</html>
Success.jsp
<%--
Created by IntelliJ IDEA.
User: Administrator
Date: 14-6-1
Time: 下午1:34
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title></title>
</head>
<body><center>
<h2>操作成功</h2><br>
<a href="/servlets/list.do">浏览图书信息</a>
</center>
</body>
</html>
Finalcheck.jsp
<%--
Created by IntelliJ IDEA.
User: Administrator
Date: 14-6-1
Time: 下午4:15
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" import="bean.bookinfo" %>
<html>
<head>
<title></title>
</head>
<body>
<center>
<table align="center" border="1" >
<tr>
<%
request.setCharacterEncoding("utf-8");
bookinfo bi=(bookinfo)request.getAttribute("bi");
%>
<th>编号</th><th>书名</th><th>作者</th><th>出版社</th><th>出版日期</th>
</tr>
<tr>
<td><%= bi.getId()%></td><td><%= bi.getName()%></td><td><%= bi.getAuthor()%></td><td><%= bi.getPress()%></td><td><%= bi.getDate()%></td>
</tr>
</table>
</center>
</body>
</html>
Successreader.jsp
<%--
Created by IntelliJ IDEA.
User: Administrator
Date: 14-6-1
Time: 下午1:34
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title></title>
</head>
<body><center>
<h2>操作成功</h2><br>
<a href="/servlets/listreader.do">浏览图书信息</a>
</center>
</body>
</html>
Failure.jsp
<%--
Created by IntelliJ IDEA.
User: Administrator
Date: 14-6-1
Time: 下午2:00
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title></title>
</head>
<body><center>
<h2>操作失败</h2>
<a href="javascript:history.back()">点击返回</a>
</center></body>
</html>
Edit.jsp
<%--
Created by IntelliJ IDEA.
User: Administrator
Date: 14-5-31
Time: 下午6:52
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" import="bean.bookinfo" %>
<html>
<head>
<title></title>
</head>
<body>
<% request.setCharacterEncoding("utf-8");
bookinfo bi=(bookinfo)request.getAttribute("bi");
%>
<center>
<form action="update.do" method="post">
<input type="hidden" name="id" value="<%= bi.getId()%>">
<table>
<h2><caption>修改信息</caption></h2>
<tr><th>书名</th><td><input type="text" value="<%= bi.getName()%>" name="name"> </td></tr>
<tr><th>作者</th><td><input type="text" value="<%= bi.getAuthor()%>" name="author"> </td></tr>
<tr><th>出版社</th><td><input type="text" value="<%= bi.getPress()%>" name="press"> </td></tr>
<tr><th>出版日期</th><td><input type="text" value="<%= bi.getDate()%>" name="date"> </td></tr>
<tr><td colspan="2" align="center"><input type="submit" value="提交"><input type="reset" value="重置"></td></tr>
</table>
</form>
</center>
</body>
</html>
Check.jsp
<%--
Created by IntelliJ IDEA.
User: Administrator
Date: 14-5-31
Time: 下午6:52
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" import="bean.bookinfo" %>
<html>
<head>
<title></title>
</head>
<body>
<% request.setCharacterEncoding("utf-8");
bookinfo bi=(bookinfo)request.getAttribute("bi");
%>
<center>
<form action="update.do" method="post">
<input type="hidden" name="id" value="<%= bi.getId()%>">
<table>
<h2><caption>修改信息</caption></h2>
<tr><th>书名</th><td><input type="text" value="<%= bi.getName()%>" name="name"> </td></tr>
<tr><th>作者</th><td><input type="text" value="<%= bi.getAuthor()%>" name="author"> </td></tr>
<tr><th>出版社</th><td><input type="text" value="<%= bi.getPress()%>" name="press"> </td></tr>
<tr><th>出版日期</th><td><input type="text" value="<%= bi.getDate()%>" name="date"> </td></tr>
<tr><td colspan="2" align="center"><input type="submit" value="提交"><input type="reset" value="重置"></td></tr>
</table>
</form>
</center>
</body>
</html>
Add.jsp
<%--
Created by IntelliJ IDEA.
User: Administrator
Date: 14-5-31
Time: 下午7:20
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title></title>
</head>
<script language="JavaScript" src="common.js"></script>
<body>
<center>
<form name="form1" onsubmit="return check()" action="/servlets/add.do" method="post">
<table align="center" border="1">
<h2><caption>图书信息</caption></h2>
<tr><th>编号</th><td><input type="text" name="id"> </td></tr>
<tr><th>书名</th><td><input type="text" name="name"> </td></tr>
<tr><th>作者</th><td><input type="text" name="author"> </td></tr>
<tr><th>出版社</th><td><input type="text" name="press"> </td></tr>
<tr><th>出版日期</th><td><input type="text" name="date"> </td></tr>
<tr><td colspan="2" align="center"><input type="submit" value="添加"><input type="reset" value="重置"></td></tr>
</table>
</form>
</center>
</body>
</html>
Common.js
function check(){
if(form1.id.value=="")
{alert ("no id!");
form1.id.focus();
return false;}
if(form1.name.value=="")
{alert("no name!");
form1.name.focus();
return false;}
if(form1.author.value=="")
{
alert("no author!");
form1.author.focus();
return false;
}
if(form1.press.value=="")
{
alert("no press!");
form1.press.focus();
return false;
}
if(form1.date.value==""){
alert("no date!")
form1.date.focus();
return false;
}
}
Bookinfo.java
package bean;
import java.lang.Exception;
import java.lang.String;
import java.lang.System;
import java.sql.*;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;
import java.util.ArrayList;
public class bookinfo{
private String id;
private String name;
private String author;
private String press;
private String date;
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setAuthor(String author) {
this.author = author;
}
public String getAuthor() {
return author;
}
public void setDate(String date) {
this.date = date;
}
public String getDate() {
return date;
}
public void setPress(String press) {
this.press = press;
}
public String getPress() {
return press;
}
public void setId(String id) {
this.id = id;
}
public String getId() {
return id;
}
public static ArrayList<bookinfo> getbooklist(){
ArrayList<bookinfo> list=new ArrayList<bookinfo>();
String sql="select * from mvc_book";
bean.dbbean jdbc=new bean.dbbean();
ResultSet rs=jdbc.executeQuery(sql);
try{
while(rs.next()){
bookinfo bi=new bookinfo();
bi.setId(rs.getString("id"));
bi.setName(rs.getString("name"));
bi.setAuthor(rs.getString("author"));
bi.setPress(rs.getString("press"));
bi.setDate(rs.getString("date"));
list.add(bi);
}
rs.close();
}
catch(SQLException e){
e.printStackTrace();
}
jdbc.close();
return list;
}
public static bookinfo getbookbyid(String id){
String sql="select * from mvc_book where id="+id;
dbbean jdbc=new dbbean();
ResultSet rs=jdbc.executeQuery(sql);
bookinfo bi = new bookinfo();
try{
if(rs.next()){
bi.setDate(rs.getString("date"));
bi.setPress(rs.getString("press"));
bi.setAuthor(rs.getString("author"));
bi.setName(rs.getString("name"));
bi.setId(rs.getString("id"));
}
rs.close();
}
catch(SQLException e){
System.out.println("no find");
}
jdbc.close();
return bi;
}
public static int updatebook(String id,String name,String author,String press,String date){
int result=0;
String sql="update mvc_book set name='"+name+"',author='"+author+"',press='"+press+"',date='"+date+"' where id="+id;
dbbean jdbc=new dbbean();
result=jdbc.executeUpdate(sql);
return result;
}
public static int deletebook(String id){
int result=0;
String sql="delete from mvc_book where id="+id;
dbbean jdbc=new dbbean();
result=jdbc.executeUpdate(sql);
return result;
}
public static int addbook(String id,String name,String author,String press,String date){
int result=0;
String sql="insert into mvc_book(id,name,author,press,date) values(id,'"+name+"','"+author+"','"+press+"','"+date+"')";
dbbean jdbc=new dbbean();
result=jdbc.executeUpdate(sql);
return result;
}
}
Dbbean.java
package bean;
import java.lang.Exception;
import java.lang.String;
import java.lang.System;
import java.sql.*;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
public class dbbean{
private String driverStr="com.mysql.jdbc.Driver";
private String connStr="jdbc:mysql://localhost:3306/book?characterEncoding=utf-8";
private String name="root";
private String password="xyh 68";
private Connection conn=null;
private Statement stmt=null;
public dbbean(){
try{
Class.forName(driverStr);
conn=DriverManager.getConnection(connStr,name,password);
stmt=conn.createStatement();
}
catch(Exception ex){
System.out.println("no connect");
}
}
public int executeUpdate(String s){
int result=0;
try{
result=stmt.executeUpdate(s);
}
catch(Exception ex){
System.out.println("update wrong!");
}
return result;
}
public ResultSet executeQuery(String s){
ResultSet rs=null;
try{
rs=stmt.executeQuery(s);
}
catch(Exception ex){
System.out.println("check wrong!");
}
return rs;
}
public void close(){
展开阅读全文