删除功能对于在线书店 [英] Delete function For an online bookshop

查看:84
本文介绍了删除功能对于在线书店的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友



我需要使用Java,JSP,Servlet,MySQL,DAO在线书店。在这个我想做的删除功能:



1.在文本框中输入图书ID(txtbox 1)

2.然后按搜索按钮

3.然后搜索该书是否在数据库中。

4.如果是,则书名应显示在第二个文本框中(txtbox 2)

5.然后删除按钮可用于删除书籍。



6.如果书籍不在数据库中,则msg应显示在页面



在这段代码中,它将书名传递给servlet,但没有显示在jsp中。你能告诉我哪里出错了吗?



这里我的jsp

Dear friends

I need to do a online bookshop using Java, JSP, Servlet, MySQL, DAO. in this delete functon i want to do :

1. enter the book id in a textbox (txtbox 1)
2. then pressing search button
3.then it search whether that book is in the db or not.
4.if yes then book name should display in 2nd textbox (txtbox 2)
5.then delete button can use for delete the book.

6. if book is not in the db then msg should display in the page

In this code it is passing book title to servlet but did not display in the jsp. can you tell me where i went wrong?

here my jsp

<div id="page">
            <form name="input" action="book" method="post">
                Book Id   :       <input type="text" name="txtBid" value ="<%=request.getAttribute("txtBid")%>" class="resizedTextbox"><br><br>
                                   
                <input type="submit" value="Search Book" onclick= <a href="main/Servelet"</a>      
                <input type="hidden" name="operation" value="searchBookbtn"><br><br>	
                Book Name : <input type="text" name="txtName" value="<%=request.getAttribute("txtName")%>" class="resizedTextbox"><br><br>
                                   
                <input type="submit" value="Delete Book" onclick= <a href="main/Servelet"</a>
                <input type="hidden" name="operation" value="deleteBookbtn">	
                <input type="submit" value="Cancel/Clear" onclick= <a href="main/Servelet"</a>
                <p><%=request.getAttribute("deleteBookMsg") %></p>
            </form>
                <br><br><br><br><br><br><br><br><br><br><br>
        </div>





这里我的servlet



here my servlet

private void searchBook(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        System.out.println("Inside searchBook");
        String bname=null;
        book b =new book();
        bookService bs = new bookServiceImpl();
        
        String b_id=request.getParameter("txtBid");
        //String b_name=request.getParameter("txtName");
        
        b.setB_id(b_id);
       
        //b.setB_title(bs.searchbook(b));
        //System.out.println(bs.searchbook(b));
        
        //bname = 
        
        System.out.println(b_id);
        if(bs.searchbook(b)!=null){             
            request.setAttribute("txtBid", b.getB_id());
            //request.setAttribute("txtName",bs.searchbook(b));
            String message = "Click Delete button to delete the above book";
            request.setAttribute("deleteBookMsg", message);
            
            request.setAttribute("txtName",b.getB_title()); 
        }else{
           String message = "Book does not Exist";
 	   request.setAttribute("deleteBookMsg", message);
        }
        RequestDispatcher rd = getServletContext().getRequestDispatcher("/deleteBook.jsp");
        rd.forward(request, response);
    }





这里我的businesslogic /服务层





here my businesslogic/service layer

public String searchbook(book b) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        System.out.println("Inside bs.searchbook");
        String book_result="";
        bookDAO bd = new bookDAOImpl();
        String bk = bd.searchBookName(b);
        //System.out.println("...."+ bk.getB_id()); 
        if(bk!=null){
             
             book_result=bk;       
        }System.out.println("**"+book_result);
        return book_result;
    } 





这里我的DAO





Here my DAO

public String searchBookName(book b) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        System.out.println("Inside book search");
        String b_result = null;
        String bname=null;
        Connection conn= null;
        PreparedStatement ptmt= null;
        ResultSet rset = null;
        try{
            conn= getConnection();             
            String queryString = "SELECT * FROM book WHERE b_id=?";
            ptmt = conn.prepareStatement(queryString);
            ptmt.setString(1, b.getB_id());
            System.out.println(b.getB_id());
            rset = ptmt.executeQuery();
            
            System.out.println(rset.first()); 
            
             if (rset.first()){
                System.out.println(rset.first());
                b_result = rset.getString(String.valueOf("b_title"));
                /*b_result = new book();
                b_result.setB_title(rset.getString(String.valueOf("b_title")));
                b_result.setB_suplier(rset.getString(String.valueOf("b_supplier")));
                b_result.setB_publisher(rset.getString(String.valueOf("b_publisher")));*/
                System.out.println("-.-.-."+b_result);
            }
        }catch(SQLException ex){
            ex.printStackTrace();
        }
        finally{try {
                    ptmt.close();
                    conn.close();
                } catch (SQLException ex) {
                    ex.printStackTrace();
                }
        }
        return b_result;	
}





感谢高级!



Thankx in advanced!

推荐答案

I已找到

I have found
b.getB_title()



但是


But where is

b.setB_title(bookTitle)





注意:请按照java惯例编写代码。类名应该以Capital开头。



Note : Please follow java convention to write code.Class name should be start with Capital .

Book b


这篇关于删除功能对于在线书店的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆