Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
HTML
<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>


here my servlet
Java
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);
    }


here my businesslogic/service layer

Java
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;
    } 


Here my DAO

Java
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!
Posted
Updated 1-Sep-13 20:31pm
v2

1 solution

I have found
Java
b.getB_title()

But where is
Java
b.setB_title(bookTitle)


Note : Please follow java convention to write code.Class name should be start with Capital .
Java
Book b
 
Share this answer
 
Comments
divya.sweety 2-Sep-13 5:37am    
Thank you..(Y)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900