错误值的错误 [英] error for wrong value

查看:78
本文介绍了错误值的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,



我正在尝试使用jsp,servlet,java和mysql以及DAO概念来建立在线图书馆系统。我开发了删除书功能。在删除之前,它正在搜索该书是否在数据库中。如果是,则用户可以删除该书。当我运行它时,它完全适用于真正的值,但是对于错误,它不会继续作为错误或正确的输出。为什么这是



这里我的jsp表格

Hey ,

I'm trying to do an online library system using jsp, servlet, java and mysql and DAO concepts. i have develop delete book function. before delete it is searching whether that book is in the db or not. if it is yes then user can delete the book. when i run it, it is working perfectly for true values but for false it did not continue as a wrong or right output. why is that

here my jsp form

<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" name="operation" 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" name="operation" value="Delete Book" onclick= <a href="main/Servelet"/> 
                <!--<input type="hidden" name="operation" value="deleteBookbtn" >-->	
                <input type="reset" value="Cancel/Clear" id="3" onclick= <a href="main/Servelet"/>                    
                <p><%=request.getAttribute("deleteBookMsg") %></p>
            </form>
                <br><br><br><br><br><br><br><br><br><br><br>
        </div>





这里我的servlet





here my servlet

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
        System.out.println("Inside book dopost");
        String operation = request.getParameter("operation");
        if(operation!=null && operation.equalsIgnoreCase("addBookbtn")){
                addBook(request,response);
        }else if(operation!=null && operation.equalsIgnoreCase("Delete Book")){
                deleteBook(request,response);
        }else if(operation!=null && operation.equalsIgnoreCase("search Book")){
                searchBook(request,response);
        }
    }







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");
        b.setB_id(b_id);
        bname = bs.searchbook(b);
        
        System.out.println(bname);
        if(bname!=null){             
            request.setAttribute("txtBid", b.getB_id());
            String message = "Click Delete button to delete the above book";
            request.setAttribute("deleteBookMsg", message);
            
            request.setAttribute("txtName",bname); 
        }else{
           String message = "Book does not Exist";
 	   request.setAttribute("deleteBookMsg", message);
        }
        RequestDispatcher rd = getServletContext().getRequestDispatcher("/deleteBook.jsp");
        rd.forward(request, response);
    }
private void deleteBook(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 deleteBook");
        book b =new book();
        bookService bs = new bookServiceImpl();  
        
        String b_id=request.getParameter("txtBid"); 
        
        b.setB_id(b_id);
        
        System.out.println("llll"+b_id);
        
        if(bs.deletebook(b)){
           String message = "Successfully Deleted "+ b.getB_id();				
           request.setAttribute("deleteBookMsg", message);
        }
        else{
           String message = "No Registered Book";
 	   request.setAttribute("deleteBookMsg", message);
        }
        RequestDispatcher rd = getServletContext().getRequestDispatcher("/deleteBook.jsp");
        rd.forward(request, response);
    }





这里我的服务/业务逻辑层代码





here my service/business logic layer code

public boolean deletebook(book b) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        System.out.println("Inside bs.deletebook");
        boolean book_result=false;
        bookDAO bd = new bookDAOImpl();
        book bk = bd.search(b);
        System.out.println("===Inside bs.deletebook");
        if(bk!=null){
             System.out.println(book_result);
             bookDAOImpl bdi = new bookDAOImpl();
             bd.deleteBook(b); 
             book_result=true;       
        }return book_result;
    }

    @Override
    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);
        if(bk!=null){             
             book_result=bk;       
        }System.out.println("**"+book_result);
        return book_result;
    } 





这里我的DAO代码





here my DAO code

@Override
    public void deleteBook(book b) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        Connection conn=null; 
        PreparedStatement ptmt= null;
        boolean result=false;
        try{ 
               conn= getConnection();
               String queryString = "DELETE FROM book WHERE b_id=?";
               ptmt = conn.prepareStatement(queryString);	              
               ptmt.setString(1, b.getB_id());
               System.out.println(b.getB_id());
               ptmt.execute();
               System.out.println(ptmt);
        }catch (Exception e) {
                e.printStackTrace();
        }finally {
                try {
                    ptmt.close();
                    conn.close();
                } catch (SQLException ex) {
                    ex.printStackTrace();
                }
        }
    }
    @Override
    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;
        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();
                }
        }System.out.println("-.-.-."+b_result);
        return b_result;	
}





有谁能回答这个问题?跟随文本来自我的控制台





Can anyone answer this? followin text is from my console

Inside book dopost
Inside searchBook
Inside bs.searchbook
Inside book search
Welcome
Connected
2
false
**

推荐答案

function fire(action){

document.formname.action = action;
document.formName.submit();
}







<input type="button" value="Search Book" onclick="fire('searchAction')" />
<input type="button" value="Delete Book" onclick="fire('deleteAction')" />


这篇关于错误值的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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