Java-Business-Application/C2/Issuing-and-Returning-a-book/English-timed
From Script | Spoken-Tutorial
Revision as of 16:11, 27 June 2014 by PoojaMoolya (Talk | contribs)
Time | Narration |
00.00 | Welcome to the spoken-tutorial on Issuing and returning a book. |
00.05 | In this tutorial, we will learn how to : |
00.08 | Fetch all the user details |
00.11 | To Issue a book |
00.13 | To return a book |
00.15 | Here we are using |
00.17 | Ubuntu Version 12.04 |
00.20 | Netbeans IDE 7.3 |
00.23 | JDK 1.7 |
00.25 | Firefox web-browser 21.0 |
00.29 | You can use any web-browser of your choice. |
00.33 | To follow this tutorial you must have knowledge of |
00.37 | Basics of Java Servlets and JSPs |
00.40 | Creating and viewing inventories |
00.44 | If not, for relevant tutorials please visit our website. |
00.48 | In the earlier tutorial, we had seen how the Admin Section works. |
00.53 | Here, in this tutorial we have added more functionalities to the Admin Section. |
00.59 | So, Let us switch to the browser. |
01.02 | Let us login again as the admin. |
01.05 | We can see that we have two more options in the Admin Section Page - List Users and Checkout/Return Book. |
01.14 | Now, let us come to the IDE. |
01.18 | We can see that in the adminsetion.jsp there are two more radio buttons. |
01.24 | One for List Users and the other for Checkout/Return Book. |
01.30 | Now, switch back to the browser. |
01.33 | We will click on the radio button for List Users. |
01.38 | It has all the details like First Name, Surname, Age, Gender and Username. |
01.48 | The steps are similar to the earlier two options. |
01.51 | We saw them in the previous tutorial. |
01.55 | Now, let us click on the next option which is to Checkout or Return Book. |
02.01 | We get a form which allows you to checkout as well as return book. |
02.06 | We will now see the code for the same. |
02.09 | Switch back to the IDE. |
02.11 | We clicked on Checkout/Return Book. |
02.14 | So menuselection is equal to checkoutbook |
02.18 | The steps are the same that we saw for List Books. |
02.23 | But here, we forward the request to checkOut.jsp using RequestDispatcher. |
02.29 | Now, let us come to checkOut dot jsp. |
02.33 | This page is similar to that of listBooks dot jsp. |
02.38 | Except that we have a radio button against each book. |
02.42 | So that we can Checkout/Return that book. |
02.46 | We also have a username field to get the username of the user who has to checkout the book. |
02.53 | We also have a Date field to set the return date of the book. |
02.59 | We set the return date as one week from current date. |
03.04 | This is done using the class Calendar. |
03.07 | The add function of this class takes two parameters. |
03.13 | The First is the present day of the year. |
03.16 | Second is the number of days to be added to the present day. |
03.21 | We have added seven days. |
03.23 | Now note that form action is equal to CheckoutServlet. |
03.29 | Now, let us come back to the browser. |
03.32 | We will now click on BookId 1. |
03.35 | Type the username as arya. |
03.38 | We see that the return date is one week from today’s date. |
03.43 | Note that the number of Available Copies is 9. |
03.48 | Click on Checkout Book. |
03.51 | We get the Checkout Success Page. |
03.55 | We will click on here to come back to Admin Section Page. |
03.59 | Again click on Checkout/Return Book. |
04.03 | We can see that the number of Available Copies reduces to 8. |
04.08 | We will see the code for this now. |
04.10 | Come back to the IDE. |
04.13 | Go to CheckoutServlet.java. |
04.16 | We have set the errorMsgs list
|
04.19 | We have set the errorMsgs in the request. |
04.23 | We get the username from the request using getParameter. |
04.28 | Similarly we get checkout_book, return_book and book id. |
04.34 | Next, we parse the BookId as Integer from the Id. |
04.40 | We validate the username and book id. |
04.44 | We also validate if Checkout_book and Return_Book is null. |
04.50 | Then, we validate if either of them is not null. |
04.55 | Here, we check if the user exists in the system using userExists method. |
05.01 | We then store the returned value of the method in userExists variable. |
05.07 | Now, we will see what we do in this method. |
05.11 | First we execute the query to check if the username exists in the table. |
05.18 | Then we initialize the integer variable userExists to 0. |
05.23 | If the username exists then we set userExists to 1. |
05.29 | We then return the value of userExists. |
05.33 | So, if the method returns 0 then, it means the user does not exist in the system. |
05.42 | else, If user exists then we call bookAlreadyIssued method. |
05.50 | We then store the returned value of the method in bookIssued. |
05.55 | Here, we check if the same book has already been issued by the same user. |
06.01 | Now, let us come to bookAlreadyIssued method. |
06.05 | Here, we have set an integer variable bookAlreadyIssued to 0. |
06.12 | We execute the query to check if a book with the same bookid is issued by the same user. |
06.18 | We get bookid from Checkout table. |
06.23 | If BookId exists then, set the variable bookAlreadyIssued to 1. |
06.30 | We then return the value of bookAlreadyIssued. |
06.34 | So, If the method returns 1 then it means the same user has already borrowed this book. |
06.43 | Now, come back to the browser. |
06.46 | Now, Let us now try to checkout the same book by the same user. |
06.51 | Type the username as arya. |
06.54 | Click on the radio button against BookId 1. |
06.59 | Then click on Checkout book. |
07.03 | We see that we get error message that the same user has already borrowed this book. |
07.10 | Now, switch back to the IDE. |
07.14 | If userExists in the system and if the checkout_book is not null, we call checkout method. |
07.22 | Let us see what we do in this method. |
07.25 | Here, we get the availablecopies for corresponding id. |
07.31 | We get this from Books table. |
07.35 | We then store the number of availablecopies into the variable availableCopies. |
07.41 | We check if availableCopies is greater than 0 and bookIssued is equal to 0. |
07.50 | We get the dateofreturn from the request and store in the returndate. |
07.56 | We then, call insertIntoCheckout. |
08.00 | We will see what we do in insertIntoCheckout method. |
08.05 | Here, we store the book_id, userName and returndate into the Checkout table. |
08.12 | Then we call decrementAvailableCopies method. |
08.16 | We will see what we do in this method. |
08.19 | Here, we execute the query to decrement the availablecopies in the Books table by 1. |
08.26 | Then we call the setCheckoutIntoRequest method. |
08.29 | Let us come to this method. |
08.32 | In this method, we set the checkout attribute into the request. |
08.38 | Then we we forward the request to successCheckout.jsp using RequestDispatcher. |
08.45 | If availableCopies is 0, then we print There are no copies of the requested book available. |
08.53 | Now, let us come to successCheckout dot jsp. |
08.58 | Here, first we get the checkout attribute from the request. |
09.03 | We then, display the success message for successful Checkout. |
09.08 | You can try out the different errors by yourself. |
09.11 | Now, let us return the book. So switch to the browser |
09.15 | Click on bookId 1 and type the username as arya. |
09.21 | Then, click on Return book. |
09.24 | We get the success message that book has been successfully returned. |
09.29 | Click on here for another checkout/return. |
09.33 | So, we come back to Admin Section Page. |
09.36 | Click on Checkout/Return Book. |
09.39 | We can see that the number of available copies has been incremented. |
09.45 | We will see the code for this. |
09.47 | Come back to the IDE. |
09.49 | Open CheckoutServlet dot java. |
09.53 | We check if userExists is equal to 1 and return_book is not equal to null. |
10.00 | Then we call returnBook method. |
10.03 | Let us come to this method. |
10.06 | Here, we select the totalcopies and availablecopies from Books table for the book id. |
10.14 | We store the totalcopies and availablecopies to totcopies and availcopies. |
10.21 | Then we check if available copies exceed the totalcopies. |
10.27 | Let us come back to the browser. |
10.30 | Let us now return a book for a user who has not borrowed the book. |
10.35 | Type the username as mdhusein. |
10.39 | Click on book id 1. |
10.42 | Then click on Return Book. |
10.44 | We can see that we get the error message The given user has not borrowed this book!! |
10.50 | Now, come back to the IDE. |
10.53 | Here, we check if bookIssued is equal to 1. |
10.57 | We then call removeFromCheckout method. |
11.01 | Let us come to this method. |
11.04 | Here, we execute the query to delete from Checkout table the entry which has returned the book. |
11.14 | Then, we call incrementAvailableCopies method. |
11.18 | Let us come to this method. |
11.21 | Here, we increment the availablecopies by 1. |
11.25 | We execute the query to update in the Books table. |
11.29 | Then we call the setReturnIntoRequest method. |
11.34 | Let us come to this method. |
11.37 | Here, we set the returnBook attribute into the request. |
11.41 | Then we forward to successReturn page using RequestDispatcher. |
11.48 | The successReturn page is similar to that we had for successCheckout page. |
11.53 | Now, come back to the browser. Come back to the login page. |
11.58 | We can see that we have a link called Visitor’s Home Page. |
12.03 | We can see that we get a list of all the books available. |
12.07 | So, In this tutorial we have learnt: |
12.10 | To list all the users |
12.12 | To fetch a book |
12.13 | To return a book. |
12.15 | To know more about spoken tutorial project, watch the video available at the following link. |
12.20 | It summarizes the Spoken Tutorial Project |
12.24 | If you do not have good bandwidth you can download and watch it |
12.28 | The Spoken Tutorial Project Team |
12.30 | Conducts workshops using spoken tutorials |
12.32 | Gives certificates to those who pass an online test |
12.36 | For more details please write to contact at spoken hyphen tutorial dot org |
12.41 | Spoken Tutorial Project is a part of the Talk to a Teacher Project |
12.44 | It is supported by the National Mission on Education through ICT, MHRD, Government of India |
12.50 | More information on this mission is available at |
12.52 | http://spoken-tutorial.org/NMEICT-Intro |
12.58 | The Library Management System has been contributed by a leading software MNC, through their Corporate Social Responsibility Programme. |
13.06 | They have also validated the content for this spoken tutorial. |
13.10 | This is Arya Ratish from IIT Bombay signing off. Thank you for joining. |