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>
here my servlet
private void searchBook(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("Inside searchBook");
String bname=null;
book b =new book();
bookService bs = new bookServiceImpl();
String b_id=request.getParameter("txtBid");
b.setB_id(b_id);
System.out.println(b_id);
if(bs.searchbook(b)!=null){
request.setAttribute("txtBid", b.getB_id());
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
public String searchbook(book b) {
System.out.println("Inside bs.searchbook");
String book_result="";
bookDAO bd = new bookDAOImpl();
String bk = bd.searchBookName(b);
if(bk!=null){
book_result=bk;
}System.out.println("**"+book_result);
return book_result;
}
Here my DAO
public String searchBookName(book b) {
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"));
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!