zoukankan      html  css  js  c++  java
  • 2020.11.28收获

    删除图书信息

    deletebook.jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <%
             Object message = request.getAttribute("message");
             if(message!=null && !"".equals(message)){
         
        %>
             <script type="text/javascript">
                  alert("<%=request.getAttribute("message")%>");
             </script>
        <%
        } 
       %>
        <h align="center">删除图书信息</h>
    <div class="content">
        <div class="main">
        <a href="guanliyuan.jsp">返回主页</a>
        <br><br>
            <form name="form" action="Servlet?method=getbyname" method="post" onsubmit="return check(form)">
                    <a>书名:</a>&nbsp;&nbsp;<input type="text" id="bookname" name="bookname" />
                    <br><br>
                    <input type="submit" value="删除" />
            </form>
            </div>
        </div>
    </body>
    </html>

    deletebook2.jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <h>信息删除</h>
        <div class="content">
            <div class="main">
            <a href="guanliyuan.jsp">返回主页</a>
            <table>
                <tr>
                    <td>编号</td>
                    <td>${book.number }</td>
                <tr>
                <tr>
                    <td>书名</td>
                    <td>${book.bookname}</td>
                <tr>
                <tr>
                    <td>作者名</td>
                    <td>${book.writername }</td>
                <tr>
                <tr>
                    <td>出版社名</td>
                    <td>${book.publishname }</td>
                <tr>
                <tr>
                    <td>可借阅数量</td>
                    <td>${book.shuliang}</td>
                <tr>
               
            </table>
            <form action="Servlet?method=deleteBook" method="post" onsubmit="return check();">
            <input type="hidden" id="bookname" name="bookname" value="${book.bookname}"> 
               <input type="submit" name="action1" value="确定删除">
            </form>
        </div>
        <script type="text/javascript">
            function check() {
                if (confirm("是否确认删除该信息?")){
                    return true;
                }else{
                    return false;
                }
            }
        </script>
    </body>
    </html>

    servlet.java

      private void getbyname(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
                req.setCharacterEncoding("utf-8");
                String bookname = req.getParameter("bookname");
                Book book = dao.getbyname(bookname);
                if(book==null)
                {
                    req.setAttribute("message", "未找到该书籍");
                    req.getRequestDispatcher("deletebook.jsp").forward(req, resp);
                }
                else 
                {
                    req.setAttribute("book", book);
                    req.getRequestDispatcher("deletebook2.jsp").forward(req,resp);
                }
            }

    Dao.java

    //删除图书
        public boolean deleteBook(String bookname)
        {
            String sql="delete from book where bookname='" + bookname + "'";
            Connection conn = DBUtil.getConn();
            Statement state = null;
            int a = 0;
            boolean f = false;
            try {
                state = conn.createStatement();
                a = state.executeUpdate(sql);
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                DBUtil.close(state, conn);
            }
            
            if (a > 0) {
                f = true;
            }
            return f;
        }
  • 相关阅读:
    趁热打铁(如何改bug)
    element el-input的autofocus失效问题解决
    为什么要将图片转为base64格式
    学习jdk1.8的Lambda和Stream
    (隐式参数)java8的方法引用之重新认识java的this关键字
    记一次惊奇面试,希望能为广大求职中的javaer提供一点经验。
    单机版ZooKeeper的安装教程
    两个对象值转换的方法(BeanUtils.copyProperties与JSONObject.parseObject对比)
    SpringBoot监控管理之Admin监管使用
    安利一个十分实用的IDEA插件--RestfulToolkit
  • 原文地址:https://www.cnblogs.com/ltw222/p/14067761.html
Copyright © 2011-2022 走看看