2024/02/14

设计的页面

主页面:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ page import="Beans.DAOImpl"%>
<%@ page import="Beans.Books"%>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Operation</title>
<script>
            function confirmDelete() {
                if (confirm("确定删除吗?")) {
                    return true;
                } else {
                    return false;
                }
            }
            window.onload = initAll;
            function initAll() {
                //alert('init');
                var delEl = document.getElementsByClassName("da");
                for (var i = 0; i < delEl.length; i++) {
                    delEl[i].onclick = confirmDelete;
                }
            }
        </script>
 
</head>
<body>
<h2>书籍信息管理</h2>
<%
 DAOImpl dao = new DAOImpl();
List<Books> list = new ArrayList();
list=dao.findAllBooks();
 
%>
<form action="doselect.jsp" method="post">
<div>
<input type="text" name="inputName">
<input type="submit" value="查询">
</div>
<hr border="1">
</form>
<jsp:useBean id="book" class="Beans.Books"/>
<table border="1">
<tr>
<th>书籍编号</th>
<th>名称</th>
<th>价格</th>
<th>操作</th>
</tr>
<%
 
    for(Books b:list){
        %>
        <tr align="center">
        <td><%=b.getBookId() %></td>
        <td><%=b.getBookName() %></td>
        <td><%=b.getPrice() %></td>
        <td><a href="update.jsp?id=<%=b.getBookId()%>">修改</a> | <a class="da" href="dodelete.jsp?name=<%=b.getBookName()%>">删除</a></td>
        </tr>
        <%
    }
 
    
 
%>
</table>
<br>
<a href="insert.jsp">添加书籍</a>
</body>
</html>

添加:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert</title>
</head>
<h2>添加书籍!</h2>
<body>
<%request.setCharacterEncoding("utf-8"); %>
 <form action="doInsert.jsp" method="post">
 <div>
     <label for="">编号:</label>
     <input type="number" name="bookId" id="id">
 </div>
 <div>
     <label for="">书名:</label>
     <input type="text" name="bookName" id="book">
 </div>
 <div>
     <label for="">价格:</label>
     <input type="number" name="price" id="price">
 </div>
 <div>
      
     <input type="submit" name="s" value="提交">
 </div>
 
 </form>
 
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="Beans.DAOImpl"%>
<%@ page import="Beans.Books"%>
 
 
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
 
<%
int id=Integer.parseInt(request.getParameter("bookId").toString());
String name=request.getParameter("bookName").toString();
double price = Double.valueOf(request.getParameter("price").toString());
 
%>
<%request.setCharacterEncoding("utf-8"); %>
<jsp:useBean id="book" class="Beans.Books" scope="page">
<jsp:setProperty name="book" property="bookId" value="<%=id%>" />
<jsp:setProperty name="book" property="bookName" value="<%=name%>" />
<jsp:setProperty name="book" property="price" value="<%=price%>" />
</jsp:useBean>
 
<%
DAOImpl dao = new DAOImpl();
dao.addBook(book);
%>
 
<jsp:forward page="insert.jsp"/>
 
</body>
</html>

修改:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>update</title>
</head>
<body>
<h2>修改书籍信息</h2>
<form action="doUpdate.jsp" method="post">
<div>
<label for="">编号:</label>
<input type="number" name="id"  value="<%=Integer.parseInt(request.getParameter("id").toString()) %>" >
</div>
<div>
<label for="">书名:</label>
<input type="text" name="book">
</div>
<div>
<label for="">价格:</label>
<input type="number" name="price">
</div>
<div>
<input type="submit" value="提交">
</div>
 
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ page import="Beans.DAOImpl"%>
<%@ page import="Beans.Books"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
int id = Integer.parseInt(request.getParameter("id").toString());
String name= request.getParameter("book").toString();
double price = Double.valueOf(request.getParameter("price"));
%>
<jsp:useBean id="book" class="Beans.Books"/>
<jsp:setProperty name="book" property="bookId" value="<%=id%>"/>
<jsp:setProperty name="book" property="bookName" value="<%=name %>"/>
<jsp:setProperty name="book" property="price" value="<%=price %>"/>
 
<%
DAOImpl dao = new DAOImpl();
dao.updateBook(book);
%>
 
<jsp:forward page="update.jsp"/>
</body>
</html>

查:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ page import="Beans.DAOImpl"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>select</title>
</head>
<body>
<jsp:useBean id="b" class="Beans.Books"/>
<%
String bookname=request.getParameter("inputName").toString();
DAOImpl dao = new DAOImpl();
b=dao.findBookByName(bookname);
%>
<jsp:setProperty property="bookId" name="b" value="<%=b.getBookId() %>"/>
<jsp:setProperty property="bookName" name="b" value="<%=b.getBookName() %>"/>
<jsp:setProperty property="price" name="b" value="<%=b.getPrice() %>"/>
<table border="1">
<tr>
<th>书籍编号</th>
<th>书名</th>
<th>价格</th>
<th>操作</th>
</tr>
<%
if(b!=null){
    
 
%>
<tr align="center">
<td>
<jsp:getProperty property="bookId" name="b"/>
</td>
<td>
<jsp:getProperty property="bookName" name="b"/>
</td>
<td>
<jsp:getProperty property="price" name="b"/>
</td>
<td><a href="update.jsp">修改</a>|<a href="delete.jsp">删除</a></td>
</tr>
<%
}
%>
</table>
 
</body>
</html>

删除:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ page import="Beans.DAOImpl"%>
<%@ page import="Beans.Books"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>delete</title>
</head>
<body>
<%
 
DAOImpl dao = new DAOImpl();
dao.deleteBookByName(request.getParameter("name"));
%>
 
<jsp:forward page="home.jsp"/>
</body>
</html>

 

posted @ 2024-02-15 04:42  伐木工熊大  阅读(6)  评论(0编辑  收藏  举报