zoukankan      html  css  js  c++  java
  • JSP图书管理系统

    allbook.jsp

        pageEncoding="UTF-8"%>
        
        <%@ page import = "java.util.*" %>
        <%@page import="com.book.service.*" %>
        <%@page import="com.book.entity.*" %>
        <%@page import="com.book.dao.*" %>
        <jsp:useBean id="bse" class="com.book.service.BookService" scope="page"></jsp:useBean>
        <jsp:useBean id="bm" class="com.book.entity.BookManage" scope="page"></jsp:useBean>
        <jsp:useBean id="dao" class="com.book.dao.BookManageDao" scope="page"></jsp:useBean>
        <%
        	List<BookManage> list = dao.checkAll();
        %>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    <link rel="stylesheet" type="text/css" href="menu.css"/>
    </head>
    <body>	
    	<main>
    		<section class="glass">
    			<div>
    			<p class="tip">全部书籍</p>
    			</div>
    			<div class="dateshow">
    				<table>
    					<tr>
    						<th>编号</th>
    						<th>书名</th>
    						<th>作者</th>
    						<th>出版日期</th>
    						<th>类型</th>
    						<th>库存</th>
    					</tr>
    					<%for(BookManage book : list){
    						%>
    						<tr>
    						<td><%=book.getB_id() %></td>
    						<td><%=book.getB_name() %></td>
    						<td><%=book.getB_author() %></td>
    						<td><%=book.getB_date() %></td>
    						<td><%=book.getB_type() %></td>
    						<td><%=book.getB_stock() %></td>
    						</tr>
    						<%
    					}
    					%>
    					
    				</table>
    			</div>
    			<div class="foot1">
    				<a href="menu.jsp">返回首页</a>
    			</div>
    		</section>
    	</main>
    </body>
    <script type="text/javascript">
    	
    </script>
    </html>
    

    borrow.jsp

     pageEncoding="UTF-8"%>
     
     <%@ page import = "java.util.*" %>
     <%@page import="com.book.service.*" %>
     <%@page import="com.book.entity.*" %>
     <%@page import="com.book.dao.*" %>
     <jsp:useBean id="bse" class="com.book.service.BookService" scope="page"></jsp:useBean>
     <jsp:useBean id="bm" class="com.book.entity.BookManage" scope="page"></jsp:useBean>
     <jsp:useBean id="dao" class="com.book.dao.BookManageDao" scope="page"></jsp:useBean>
     <%
     	List<BookManage> list = dao.checkAll();
     	int id = 0;
     %>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    <link rel="stylesheet" type="text/css" href="menu.css"/>
    </head>
    <body>	
     <main>
     	<section class="glass">
     		<div>
     		<p class="tip">请输入借出书籍的编号、书名,谢谢!</p>
     		</div>
     		<form action="onborrow.jsp" method="post">
     			<p>书籍编号:</p>
     			<input type="text" id="bnumber" name="bnumber"/>
     			<p>书籍名:</p>
     			<input type="text" id="bname" name="bname"/>
     			<input type="submit" id="submit" name="submit" value="借书"/>
     		</form>
     		<% 
     			String jud = (String)session.getAttribute("jud");
     			if(jud == "true"){
     				%>
     				<script>
     					alert("借书成功!");
     				</script>
     				<%
     				session.setAttribute("jud", "");
     			}else if(jud == "false"){
     				%>
     				<script>
     					alert("借书失败!");
     				</script>
     				<%
     				session.setAttribute("jud", "");
     			}
     		%>
     		<div class="foot">
     			<a href="menu.jsp">返回首页</a>
     		</div>
     	</section>
     </main>
    </body>
    <script type="text/javascript">
     function judge(){
     	var nu = document.getElementById("bnumber");
     	var na = document.getElementById("bname");
     	if(parseInt(nu.value) !== null && na.value !== null){
     		return true;
     	}else{
     		return false;
     	}
     }
    </script>
    
    </html>
    

    check.jsp

        pageEncoding="UTF-8"%>
        <%@ page import = "java.util.*" %>
        <%@page import="com.book.service.*" %>
        <%@page import="com.book.entity.*" %>
        <%@page import="com.book.dao.*" %>
        <jsp:useBean id="bse" class="com.book.service.BookService" scope="page"></jsp:useBean>
        <jsp:useBean id="bm" class="com.book.entity.BookManage" scope="page"></jsp:useBean>
        <jsp:useBean id="dao" class="com.book.dao.BookManageDao" scope="page"></jsp:useBean>
        
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    <link rel="stylesheet" type="text/css" href="menu.css"/>
    </head>
    <body>
    	<main>
    		<section class="glass">
    			<div>
    			<p class="tip">请输入要查询的书籍的编号、书名,谢谢!</p>
    			</div>
    			<form action="oncheck.jsp" method="post">
    				<p>书籍编号:</p>
    				<input type="text" id="bnumber" name="bnumber"/>
    				<p>书籍名:</p>
    				<input type="text" id="bname" name="bname"/>
    				<input type="submit" id="submit" name="submit" value="查询"/>
    			</form>
    			<div class="foot">
    				<a href="menu.jsp">返回首页</a>
    			</div>
    		</section>
    	</main>
    </body>
    <script type="text/javascript">
    	function judge(){
    		var nu = document.getElementById("bnumber");
    		var na = document.getElementById("bname");
    		if(parseInt(nu.value) !== null && na.value !== null){
    			return true;
    		}else{
    			return false;
    		}
    	}
    </script>
    
    
    </html>
    
    *{
    	margin: 0;
    	padding: 0;
        box-sizing: border-box;
    }
    
    
    main{
    	min-height:100vh;
    	background:linear-gradient(to right top,#65dfc9,#6cdbeb);
    	display:flex;
    	align-items: center;
    	justify-content: center;
    }
    
    .glass{
    	background: white;
    	min-height: 80vh;
    	60%;
    	background: linear-gradient(to right bottom,rgba(255,255,255,0.7),rgba(255,255,255,0.3));
    	border-radius: 2rem;
    	z-index: 2;
        backdrop-filter: blur(2rem);
    }
    
    .circle1,.circle2{
    	background:white;
    	background: linear-gradient(to right bottom,rgba(255,255,255,0.8),rgba(255,255,255,0.3));
    	height: 20rem;
    	 20rem;
    	position:absolute;
        border-radius: 50%;
    }
    .circle1{
        top: 5%;
        right: 15%;
    }
    .circle2{
        top: 60%;
        left: 10%;
    }
    .title{
        position: relative;
        top: 50px;
    }
    .element{
        height: 120px;
         120px;
        float: left;
        align-items: center;
        margin: 20px;
    }
    .link{
        background:rgb(109, 211, 236);
        background: linear-gradient(to right bottom,rgba(255,255,255,0.8),rgba(255,255,255,0.3));
        height: 120px;
         120px;
        border-radius: 50%;
        box-shadow: 5px 5px 5px rgba(0,0,0,0.2);
        display: flex;
        justify-content: center;
        align-items: center;
        
    }
    .links{
        height: 60%;
         100%;
        position: relative;
        top: 130px;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    
    
    img{
         80px;
        height: 80px;
        
    }
    a{
        font-family:Georgia, 'Times New Roman', Times, serif;
        position: relative;
        display: flex;
        justify-content: center;
        align-items: center;
        color: #26cce6;
        text-decoration: none;
        margin-top: 25px;
        font-weight: 500;
        border-radius: 20px;
        background-color: rgba(255,255,255,0.2);
        padding: 8px 20px;
        box-shadow: 0px 0px 10px rgba(0,0,0,0.2);
    }
    h1{
        text-align: center;
        font-size: 60px;
        color: #26cce6;
    }
    .tip{
    	position: relative;
        top: 20px;
        font-size: 20px;
        color: #26cce6;
        text-decoration: none;
        margin-top: 25px;
        font-weight: 500;
        border-radius: 20px;
        background-color: rgba(255,255,255,0.2);
        padding: 8px 20px;
    }
    table{
    	 100%;
    	position: relative;
        top: 50px;
        text-align:center;
        vertical-align:middle;
        border-top: 1px solid #999;
        border-left: 1px solid #999;
        border-spacing: 0;/*去掉单元格间隙*/
    }
    table th{
    	border-bottom: 1px solid #999;
        border-right: 1px solid #999;
    }
    table td{
    	border-bottom: 1px solid #999;
        border-right: 1px solid #999;
    }
    .checkshow{
    	 100%;
        position: relative;
        top: 30px;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    .tab1{
    	 100%;
    	position: relative;
        top: 20px;
        text-align:center;
        vertical-align:middle;
        border-top: 1px solid #999;
        border-left: 1px solid #999;
        border-spacing: 0;/*去掉单元格间隙*/
    }
    .tab1>th{
    	border-bottom: 1px solid #999;
        border-right: 1px solid #999;
    }
    .tad1>td{
    	border-bottom: 1px solid #999;
        border-right: 1px solid #999;
    }
    form{
    	position: relative;
        top: 130px;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    .foot{
    	 100%;
        position: relative;
        top: 430px;
        right: 20px;
        display: flex;
        justify-content: flex-end;
        align-items: flex-end;
    }
    .foot1{
    	 100%;
        position: relative;
        top: 330px;
        right: 20px;
        display: flex;
        justify-content: flex-end;
        align-items: flex-end;
    }
    
        pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>图书管理系统</title>
    <link rel="stylesheet" type="text/css" href="menu.css"/>
    </head>
    <body>
        <main>
    		<section class="glass">
                <div class="title">
                    <h1>图书管理系统</h1>
                </div>
                <div class="links">
                    <div class="element">
                        <div class="link">
                            <img src="./images/borrow1.png" alt=""/>
                        </div>
                        <a href="borrow.jsp">借阅</a>
                    </div>
                    <div class="element">
                        <div class="link">
                            <img src="./images/return1.png" alt=""/>
                        </div>
                        <a href="return.jsp">还书</a>
                    </div>
                    <div class="element">
                        <div class="link">
                            <img src="./images/check1.png" alt=""/>
                        </div>
                        <a href="check.jsp">查询</a>
                    </div>
                    <div class="element">
                        <div class="link">
                            <img src="./images/book1.png" alt=""/>
                        </div>
                        <a href="allbook.jsp">书库</a>
                    </div>
                </div>
    
    		</section>
    	</main>
        <div class="circle1"></div>
        <div class="circle2"></div>
    </body>
    </html>```
    
    ##onborrow.jsp
    ```<%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
        
        <%@ page import = "java.util.*" %>
        <%@page import="com.book.service.*" %>
        <%@page import="com.book.entity.*" %>
        <%@page import="com.book.dao.*" %>
        <jsp:useBean id="bse" class="com.book.service.BookService" scope="page"></jsp:useBean>
        <jsp:useBean id="bm" class="com.book.entity.BookManage" scope="page"></jsp:useBean>
        <jsp:useBean id="dao" class="com.book.dao.BookManageDao" scope="page"></jsp:useBean>
        <%
        	request.setCharacterEncoding("UTF-8");
        	String id = request.getParameter("bnumber");
    		String name = request.getParameter("bname");
    		
    		String i = "false";
    
    		int ids = Integer.valueOf(id);
    		if(dao.update(ids, name) != 0){
    			i = "true";	
    			session.setAttribute("jud", i);
    			response.sendRedirect("borrow.jsp");
    		}else{
    			i = "false";	
    			session.setAttribute("jud", i);
    			response.sendRedirect("borrow.jsp");
    		}
        %>
        
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    </body>
    </html>```
    ##oncheck.jsp
    ```<%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
        
        <%@ page import = "java.util.*" %>
        <%@page import="com.book.service.*" %>
        <%@page import="com.book.entity.*" %>
        <%@page import="com.book.dao.*" %>
        <jsp:useBean id="bse" class="com.book.service.BookService" scope="page"></jsp:useBean>
        <jsp:useBean id="bm" class="com.book.entity.BookManage" scope="page"></jsp:useBean>
        <jsp:useBean id="dao" class="com.book.dao.BookManageDao" scope="page"></jsp:useBean>
        <%
    	    request.setCharacterEncoding("UTF-8");
    		String id = request.getParameter("bnumber");
    		String name = request.getParameter("bname");
    		
    		String i = "false";
    	
    		int ids = Integer.valueOf(id);
        	List<BookManage> list = dao.check(ids,name);
        %>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    <link rel="stylesheet" type="text/css" href="menu.css"/>
    </head>
    <body>	
    	<main>
    		<section class="glass">
    			<div>
    			<p class="tip">查找到的信息</p>
    			</div>
    			<div class="checkshow">
    				<table class="tab1">
    					<tr>
    						<th>编号</th>
    						<th>书名</th>
    						<th>作者</th>
    						<th>出版日期</th>
    						<th>类型</th>
    						<th>库存</th>
    					</tr>
    					<%for(BookManage book : list){
    						%>
    						<tr>
    						<td><%=book.getB_id() %></td>
    						<td><%=book.getB_name() %></td>
    						<td><%=book.getB_author() %></td>
    						<td><%=book.getB_date() %></td>
    						<td><%=book.getB_type() %></td>
    						<td><%=book.getB_stock() %></td>
    						</tr>
    						<%
    					}
    					%>
    					
    				</table>
    			</div>
    			<div class="foot">
    				<a href="menu.jsp">返回首页</a>
    			</div>
    		</section>
    	</main>
    </body>
    <script type="text/javascript">
    	
    </script>
    </html>
    

    onreturn.jsp

        pageEncoding="UTF-8"%>
        
        <%@ page import = "java.util.*" %>
        <%@page import="com.book.service.*" %>
        <%@page import="com.book.entity.*" %>
        <%@page import="com.book.dao.*" %>
        <jsp:useBean id="bse" class="com.book.service.BookService" scope="page"></jsp:useBean>
        <jsp:useBean id="bm" class="com.book.entity.BookManage" scope="page"></jsp:useBean>
        <jsp:useBean id="dao" class="com.book.dao.BookManageDao" scope="page"></jsp:useBean>
        <%
        	request.setCharacterEncoding("UTF-8");
        	String id = request.getParameter("bnumber");
    		String name = request.getParameter("bname");
    		
    		String i = "false";
    
    		int ids = Integer.valueOf(id);
    		if(dao.add(ids, name) != 0){
    			i = "true";	
    			session.setAttribute("jud", i);
    			response.sendRedirect("return.jsp");
    		}else{
    			i = "false";	
    			session.setAttribute("jud", i);
    			response.sendRedirect("return.jsp");
    		}
        %>
        
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    </body>
    </html>
    

    return.jsp

        pageEncoding="UTF-8"%>
        
        <%@ page import = "java.util.*" %>
        <%@page import="com.book.service.*" %>
        <%@page import="com.book.entity.*" %>
        <%@page import="com.book.dao.*" %>
        <jsp:useBean id="bse" class="com.book.service.BookService" scope="page"></jsp:useBean>
        <jsp:useBean id="bm" class="com.book.entity.BookManage" scope="page"></jsp:useBean>
        <jsp:useBean id="dao" class="com.book.dao.BookManageDao" scope="page"></jsp:useBean>
        <%
        	int id = 0;
        %>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    <link rel="stylesheet" type="text/css" href="menu.css"/>
    </head>
    <body>	
    	<main>
    		<section class="glass">
    			<div>
    			<p class="tip">请输入归还书籍的编号、书名,谢谢!</p>
    			</div>
    			<form action="onreturn.jsp" method="post">
    				<p>书籍编号:</p>
    				<input type="text" id="bnumber" name="bnumber"/>
    				<p>书籍名:</p>
    				<input type="text" id="bname" name="bname"/>
    				<input type="submit" id="submit" name="submit" value="还书"/>
    			</form>
    			<% 
    				String jud = (String)session.getAttribute("jud");
    				if(jud == "true"){
    					%>
    					<script>
    						alert("还书成功!");
    					</script>
    					<%
    					session.setAttribute("jud", "");
    				}else if(jud == "false"){
    					%>
    					<script>
    						alert("还书失败!");
    					</script>
    					<%
    					session.setAttribute("jud", "");
    				}
    			%>
    			<div class="foot">
    				<a href="menu.jsp">返回首页</a>
    			</div>
    		</section>
    	</main>
    </body>
    <script type="text/javascript">
    	function judge(){
    		var nu = document.getElementById("bnumber");
    		var na = document.getElementById("bname");
    		if(parseInt(nu.value) !== null && na.value !== null){
    			return true;
    		}else{
    			return false;
    		}
    	}
    </script>
    
    </html>
    

    BookManageDao.java

    
    import java.awt.print.Book;
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.util.ArrayList;
    import java.util.List;
    
    import com.book.entity.BookManage;
    
    public class BookManageDao extends BaseDao{
    
    	
    	//check *
    	public List<BookManage> checkAll() {
    		List<BookManage> list = new ArrayList<BookManage>();
    		Connection conn = null;
    		PreparedStatement ps = null;
    		ResultSet rs = null;
    		try {
    			conn = getConnection();
    			//SQL code
    			String sql = "select * from bookinfo";
    			ps = conn.prepareStatement(sql);
    			//run
    			rs = ps.executeQuery();//rs is a from
    			while(rs.next()) {
    				//everyone is a object
    				BookManage b = new BookManage();
    				b.setB_id(rs.getInt(1));
    				b.setB_name(rs.getString(2));
    				b.setB_author(rs.getString(3));
    				b.setB_date(rs.getString(4));
    				b.setB_type(rs.getInt(5));
    				b.setB_stock(rs.getInt(6));
    				list.add(b);
    			}
    		} catch (Exception e) {
    			// TODO: handle exception
    			e.printStackTrace();
    		}finally {
    			closeAll(conn, ps, null);
    		}
    		return list;
    	}
    	
    	
    	//check query
    		public List<BookManage> check(int bid, String bname) {
    			List<BookManage> list = new ArrayList<BookManage>();
    			Connection conn = null;
    			PreparedStatement ps = null;
    			ResultSet rs = null;
    			try {
    				conn = getConnection();
    				//SQL code
    				String sql = "select * from bookinfo where b_id=? and b_name=?";
    				ps = conn.prepareStatement(sql);
    				ps.setInt(1, bid);
    				ps.setString(2, bname);
    				//run
    				rs = ps.executeQuery();//rs is a from
    				while(rs.next()) {
    					//everyone is a object
    					BookManage b = new BookManage();
    					b.setB_id(rs.getInt(1));
    					b.setB_name(rs.getString(2));
    					b.setB_author(rs.getString(3));
    					b.setB_date(rs.getString(4));
    					b.setB_type(rs.getInt(5));
    					b.setB_stock(rs.getInt(6));
    					list.add(b);
    				}
    			} catch (Exception e) {
    				// TODO: handle exception
    				e.printStackTrace();
    			}finally {
    				closeAll(conn, ps, null);
    			}
    			return list;
    		}
    		
    	
    	//add
    	public int add(int bid, String bname) {
    		int i = 0;
    		Connection conn = null;
    		PreparedStatement ps = null;
    		
    		try {
    			//link
    			 conn = getConnection();
    			//SQL code
    			 String sql = "update bookinfo set b_stock=b_stock+1 where b_id=? and b_name=?";
    			//given ?
    			 ps = conn.prepareStatement(sql);
    			 ps.setInt(1, bid);
    			 ps.setString(2, bname);
    			 //run
    			 i = ps.executeUpdate();
    		} catch (Exception e) {
    			// TODO: handle exception
    			e.printStackTrace();
    		}finally {
    			closeAll(conn, ps, null);
    		}
    		
    		return i;
    		
    	}
    	
    	
    	//update
    	public int update(int bid, String bname) {
    		int i = 0;
    		Connection conn = null;
    		PreparedStatement ps = null;
    		 try {
    			//link
    			 conn = getConnection();
    			//SQL code
    			 String sql = "update bookinfo set b_stock=b_stock-1 where b_id=? and b_name=?";
    			//given ?
    			 ps = conn.prepareStatement(sql);
    			 ps.setInt(1, bid);
    			 ps.setString(2, bname);
    			 //run
    			 i = ps.executeUpdate();
    		} catch (Exception e) {
    			// TODO: handle exception
    			e.printStackTrace();
    		}finally {
    			closeAll(conn, ps, null);
    		}
    		
    		return i;
    	}
    	
    	
    	
    }
    

    BookManage.java

    
    public class BookManage {
    	//	b_id bigint not null auto_increment,
    	//	b_name varchar(50) not null,
    	//	b_author varchar(50) not null,
    	//	b_date datetime not null,
    	//	b_type int not null
    	//  b_stock int(50) not null
    	
    	private int b_id;
    	private String b_name;
    	private String b_author;
    	private String b_date;
    	private int b_type;
    	private int b_stock;
    	
    	//空构造
    	public BookManage() {
    		super();
    	}
    
    	//	构造
    	public BookManage(int b_id, String b_name, String b_author, String b_date, int b_type, int b_stock) {
    		super();
    		this.b_id = b_id;
    		this.b_name = b_name;
    		this.b_author = b_author;
    		this.b_date = b_date;
    		this.b_type = b_type;
    		this.b_stock = b_stock;
    	}
    
    
    	public int getB_id() {
    		return b_id;
    	}
    
    
    	public void setB_id(int b_id) {
    		this.b_id = b_id;
    	}
    
    
    	public String getB_name() {
    		return b_name;
    	}
    
    
    	public void setB_name(String b_name) {
    		this.b_name = b_name;
    	}
    
    
    	public String getB_author() {
    		return b_author;
    	}
    
    
    	public void setB_author(String b_author) {
    		this.b_author = b_author;
    	}
    
    
    	public String getB_date() {
    		return b_date;
    	}
    
    
    	public void setB_date(String b_date) {
    		this.b_date = b_date;
    	}
    
    	public int getB_type() {
    		return b_type;
    	}
    
    	public void setB_type(int b_type) {
    		this.b_type = b_type;
    	}
    
    	public int getB_stock() {
    		return b_stock;
    	}
    
    	public void setB_stock(int b_stock) {
    		this.b_stock = b_stock;
    	}
    
    
    	
    	
    }
    

    BaseDao.java

    
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    
    public class BaseDao {
    
    	
    	//open connection
    	protected Connection getConnection(){
    		Connection conn = null;
    		
    		try {
    			Class.forName("com.mysql.jdbc.Driver");
    			conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/book","root","root");
    		} catch (Exception e) {
    			// TODO: handle exception
    			e.printStackTrace();
    		}
    		
    		return conn;
    		
    	}
    	
    	
    	//close connection
    	protected void closeAll(Connection con,PreparedStatement ps,ResultSet rs) {
    		try {
    			if(rs != null) {
    				rs.close();
    			}
    			if(ps != null) {
    				ps.close();
    			}
    			if(con != null) {
    				con.close();
    			}
    		} catch (Exception e) {
    			// TODO: handle exception
    			e.printStackTrace();
    		}
    	}
    	
    }
    

    image
    image
    image
    image

  • 相关阅读:
    匿名函数
    内置函数
    基础函数--3
    基础函数(2)
    基础函数(1)
    文件的相关操作
    知识点补充,set集合,深浅copy
    is 和 ==的区别
    Django-form组件中过滤当前用户信息
    Django的常用模块引入整理
  • 原文地址:https://www.cnblogs.com/yunlan/p/14749896.html
Copyright © 2011-2022 走看看