Difference between revisions of "Java-Business-Application/C2/Issuing-and-Returning-a-book/English-timed"
From Script | Spoken-Tutorial
PoojaMoolya (Talk | contribs) |
|||
Line 4: | Line 4: | ||
|- | |- | ||
− | | 00 | + | | 00:00 |
| Welcome to the spoken-tutorial on '''Issuing and returning a book.''' | | Welcome to the spoken-tutorial on '''Issuing and returning a book.''' | ||
|- | |- | ||
− | | 00 | + | | 00:05 |
| In this tutorial, we will learn how to : | | In this tutorial, we will learn how to : | ||
|- | |- | ||
− | | 00 | + | | 00:08 |
| Fetch all the user details | | Fetch all the user details | ||
|- | |- | ||
− | | 00 | + | | 00:11 |
| To Issue a book | | To Issue a book | ||
|- | |- | ||
− | | 00 | + | | 00:13 |
| To return a book | | To return a book | ||
|- | |- | ||
− | | 00 | + | | 00:15 |
| Here we are using | | Here we are using | ||
|- | |- | ||
− | | 00 | + | | 00:17 |
| Ubuntu Version 12.04 | | Ubuntu Version 12.04 | ||
|- | |- | ||
− | | 00 | + | | 00:20 |
| Netbeans IDE 7.3 | | Netbeans IDE 7.3 | ||
|- | |- | ||
− | | 00 | + | | 00:23 |
| JDK 1.7 | | JDK 1.7 | ||
|- | |- | ||
− | | 00 | + | | 00:25 |
| Firefox web-browser 21.0 | | Firefox web-browser 21.0 | ||
|- | |- | ||
− | | 00 | + | | 00:29 |
| You can use any web-browser of your choice. | | You can use any web-browser of your choice. | ||
|- | |- | ||
− | | 00 | + | | 00:33 |
| To follow this tutorial you must have knowledge of | | To follow this tutorial you must have knowledge of | ||
|- | |- | ||
− | | 00 | + | | 00:37 |
| Basics of '''Java Servlets '''and '''JSPs''' | | Basics of '''Java Servlets '''and '''JSPs''' | ||
|- | |- | ||
− | | 00 | + | | 00:40 |
| Creating and viewing inventories | | Creating and viewing inventories | ||
|- | |- | ||
− | | 00 | + | | 00:44 |
| If not, for relevant tutorials please visit our website. | | If not, for relevant tutorials please visit our website. | ||
|- | |- | ||
− | | 00 | + | | 00:48 |
| In the earlier tutorial, we had seen how the '''Admin Section''' works. | | In the earlier tutorial, we had seen how the '''Admin Section''' works. | ||
|- | |- | ||
− | | 00 | + | | 00:53 |
| Here, in this tutorial we have added more functionalities to the '''Admin Section.''' | | Here, in this tutorial we have added more functionalities to the '''Admin Section.''' | ||
|- | |- | ||
− | | 00 | + | | 00:59 |
| So, Let us switch to the '''browser.''' | | So, Let us switch to the '''browser.''' | ||
|- | |- | ||
− | | 01 | + | | 01:02 |
| Let us login again as the '''admin.''' | | Let us login again as the '''admin.''' | ||
|- | |- | ||
− | | 01 | + | | 01:05 |
| We can see that we have two more options in the '''Admin Section Page - List Users '''and '''Checkout/Return Book.''' | | We can see that we have two more options in the '''Admin Section Page - List Users '''and '''Checkout/Return Book.''' | ||
|- | |- | ||
− | | 01 | + | | 01:14 |
| Now, let us come to the '''IDE. ''' | | Now, let us come to the '''IDE. ''' | ||
|- | |- | ||
− | | 01 | + | | 01:18 |
| We can see that in the '''adminsetion.jsp''' there are two more '''radio buttons.''' | | We can see that in the '''adminsetion.jsp''' there are two more '''radio buttons.''' | ||
|- | |- | ||
− | | 01 | + | | 01:24 |
| One for '''List Users '''and the other for '''Checkout/Return Book.''' | | One for '''List Users '''and the other for '''Checkout/Return Book.''' | ||
|- | |- | ||
− | | 01 | + | | 01:30 |
|Now, switch back to the '''browser.''' | |Now, switch back to the '''browser.''' | ||
|- | |- | ||
− | | 01 | + | | 01:33 |
| We will click on the '''radio button '''for '''List Users.''' | | We will click on the '''radio button '''for '''List Users.''' | ||
|- | |- | ||
− | |01 | + | |01:38 |
|It has all the details like '''First Name, Surname, Age, Gender and Username.''' | |It has all the details like '''First Name, Surname, Age, Gender and Username.''' | ||
|- | |- | ||
− | | 01 | + | | 01:48 |
|The steps are similar to the earlier two options. | |The steps are similar to the earlier two options. | ||
|- | |- | ||
− | | 01 | + | | 01:51 |
| We saw them in the previous tutorial. | | We saw them in the previous tutorial. | ||
|- | |- | ||
− | | 01 | + | | 01:55 |
| Now, let us click on the next option which is to '''Checkout '''or '''Return Book.''' | | Now, let us click on the next option which is to '''Checkout '''or '''Return Book.''' | ||
|- | |- | ||
− | | 02 | + | | 02:01 |
| We get a '''form '''which allows you to '''checkout '''as well as '''return book.''' | | We get a '''form '''which allows you to '''checkout '''as well as '''return book.''' | ||
|- | |- | ||
− | | 02 | + | | 02:06 |
| We will now see the code for the same. | | We will now see the code for the same. | ||
|- | |- | ||
− | | 02 | + | | 02:09 |
| Switch back to the '''IDE.''' | | Switch back to the '''IDE.''' | ||
|- | |- | ||
− | | 02 | + | | 02:11 |
| We clicked on '''Checkout/Return Book.''' | | We clicked on '''Checkout/Return Book.''' | ||
|- | |- | ||
− | | 02 | + | | 02:14 |
| So '''menuselection '''is equal to '''checkoutbook''' | | So '''menuselection '''is equal to '''checkoutbook''' | ||
|- | |- | ||
− | | 02 | + | | 02:18 |
| The steps are the same that we saw for '''List Books.''' | | The steps are the same that we saw for '''List Books.''' | ||
|- | |- | ||
− | | 02 | + | | 02:23 |
| But here, we forward the '''request '''to '''checkOut.jsp '''using '''RequestDispatcher.''' | | But here, we forward the '''request '''to '''checkOut.jsp '''using '''RequestDispatcher.''' | ||
|- | |- | ||
− | | 02 | + | | 02:29 |
| Now, let us come to '''checkOut '''''dot '''''jsp.''' | | Now, let us come to '''checkOut '''''dot '''''jsp.''' | ||
|- | |- | ||
− | | 02 | + | | 02:33 |
| This page is similar to that of '''listBooks '''''dot '''''jsp.''' | | This page is similar to that of '''listBooks '''''dot '''''jsp.''' | ||
|- | |- | ||
− | | 02 | + | | 02:38 |
| Except that we have a '''radio button '''against each '''book.''' | | Except that we have a '''radio button '''against each '''book.''' | ||
|- | |- | ||
− | | 02 | + | | 02:42 |
| So that we can '''Checkout/Return ''' that '''book.''' | | So that we can '''Checkout/Return ''' that '''book.''' | ||
|- | |- | ||
− | | 02 | + | | 02:46 |
| We also have a '''username field '''to get the '''username '''of the '''user '''who has to '''checkout''' the book. | | We also have a '''username field '''to get the '''username '''of the '''user '''who has to '''checkout''' the book. | ||
|- | |- | ||
− | | 02 | + | | 02:53 |
| We also have a '''Date field '''to set the '''return date '''of the book. | | We also have a '''Date field '''to set the '''return date '''of the book. | ||
|- | |- | ||
− | | 02 | + | | 02:59 |
| We set the return date as one week from current date. | | We set the return date as one week from current date. | ||
|- | |- | ||
− | | 03 | + | | 03:04 |
| This is done using the class '''Calendar.''' | | This is done using the class '''Calendar.''' | ||
|- | |- | ||
− | | 03 | + | | 03:07 |
| The add function of this class takes two parameters. | | The add function of this class takes two parameters. | ||
|- | |- | ||
− | | 03 | + | | 03:13 |
| The First is the present day of the year. | | The First is the present day of the year. | ||
|- | |- | ||
− | | 03 | + | | 03:16 |
| Second is the number of days to be added to the present day. | | Second is the number of days to be added to the present day. | ||
|- | |- | ||
− | | 03 | + | | 03:21 |
| We have added seven days. | | We have added seven days. | ||
|- | |- | ||
− | | 03 | + | | 03:23 |
| Now note that '''form action '''is equal to '''CheckoutServlet.''' | | Now note that '''form action '''is equal to '''CheckoutServlet.''' | ||
|- | |- | ||
− | | 03 | + | | 03:29 |
| Now, let us come back to the '''browser.''' | | Now, let us come back to the '''browser.''' | ||
|- | |- | ||
− | | 03 | + | | 03:32 |
| We will now click on '''BookId 1.''' | | We will now click on '''BookId 1.''' | ||
|- | |- | ||
− | | 03 | + | | 03:35 |
| Type the '''username '''as '''arya. ''' | | Type the '''username '''as '''arya. ''' | ||
|- | |- | ||
− | | 03 | + | | 03:38 |
| We see that the''' return date '''is one week from today’s date. | | We see that the''' return date '''is one week from today’s date. | ||
|- | |- | ||
− | | 03 | + | | 03:43 |
| Note that the number of '''Available Copies '''is '''9.''' | | Note that the number of '''Available Copies '''is '''9.''' | ||
|- | |- | ||
− | | 03 | + | | 03:48 |
| Click on '''Checkout Book.''' | | Click on '''Checkout Book.''' | ||
|- | |- | ||
− | | 03 | + | | 03:51 |
| We get the '''Checkout Success Page.''' | | We get the '''Checkout Success Page.''' | ||
|- | |- | ||
− | | 03 | + | | 03:55 |
| We will click on '''here '''to come back to '''Admin Section Page.''' | | We will click on '''here '''to come back to '''Admin Section Page.''' | ||
|- | |- | ||
− | | 03 | + | | 03:59 |
| Again click on '''Checkout/Return Book.''' | | Again click on '''Checkout/Return Book.''' | ||
|- | |- | ||
− | | 04 | + | | 04:03 |
| We can see that the number of '''Available Copies '''reduces to '''8.''' | | We can see that the number of '''Available Copies '''reduces to '''8.''' | ||
|- | |- | ||
− | | 04 | + | | 04:08 |
|We will see the code for this now. | |We will see the code for this now. | ||
|- | |- | ||
− | | 04 | + | | 04:10 |
| Come back to the '''IDE.''' | | Come back to the '''IDE.''' | ||
|- | |- | ||
− | | 04 | + | | 04:13 |
| Go to '''CheckoutServlet.java.''' | | Go to '''CheckoutServlet.java.''' | ||
|- | |- | ||
− | | 04 | + | | 04:16 |
|We have set the '''errorMsgs''' list | |We have set the '''errorMsgs''' list | ||
− | |||
|- | |- | ||
− | | 04 | + | | 04:19 |
|We have set the '''errorMsgs '''in the '''request.''' | |We have set the '''errorMsgs '''in the '''request.''' | ||
|- | |- | ||
− | | 04 | + | | 04:23 |
| We get the '''username '''from the '''request using getParameter.''' | | We get the '''username '''from the '''request using getParameter.''' | ||
|- | |- | ||
− | | 04 | + | | 04:28 |
| Similarly we get '''checkout_book, return_book '''and '''book id.''' | | Similarly we get '''checkout_book, return_book '''and '''book id.''' | ||
|- | |- | ||
− | | 04 | + | | 04:34 |
| Next, we parse the '''BookId '''as '''Integer '''from the '''Id.''' | | Next, we parse the '''BookId '''as '''Integer '''from the '''Id.''' | ||
|- | |- | ||
− | | 04 | + | | 04:40 |
| We validate the '''username '''and '''book id.''' | | We validate the '''username '''and '''book id.''' | ||
|- | |- | ||
− | | 04 | + | | 04:44 |
| We also validate if '''Checkout_book '''and '''Return_Book '''is '''null.''' | | We also validate if '''Checkout_book '''and '''Return_Book '''is '''null.''' | ||
|- | |- | ||
− | | 04 | + | | 04:50 |
|Then, we validate if either of them is not '''null.''' | |Then, we validate if either of them is not '''null.''' | ||
|- | |- | ||
− | | 04 | + | | 04:55 |
|Here, we check if the '''user '''exists in the''' system '''using '''userExists method.''' | |Here, we check if the '''user '''exists in the''' system '''using '''userExists method.''' | ||
|- | |- | ||
− | | 05 | + | | 05:01 |
| We then store the returned value of the '''method '''in '''userExists variable.''' | | We then store the returned value of the '''method '''in '''userExists variable.''' | ||
|- | |- | ||
− | | 05 | + | | 05:07 |
| Now, we will see what we do in this '''method.''' | | Now, we will see what we do in this '''method.''' | ||
|- | |- | ||
− | |05 | + | |05:11 |
|First we execute the query to check if the '''username '''exists in the '''table.''' | |First we execute the query to check if the '''username '''exists in the '''table.''' | ||
|- | |- | ||
− | | 05 | + | | 05:18 |
| Then we initialize the '''integer variable''' '''userExists '''to '''0.''' | | Then we initialize the '''integer variable''' '''userExists '''to '''0.''' | ||
|- | |- | ||
− | | 05 | + | | 05:23 |
| If the '''username '''exists then we set '''userExists '''to '''1.''' | | If the '''username '''exists then we set '''userExists '''to '''1.''' | ||
|- | |- | ||
− | | 05 | + | | 05:29 |
| We then return the value of '''userExists.''' | | We then return the value of '''userExists.''' | ||
|- | |- | ||
− | | 05 | + | | 05:33 |
| So, if the '''method '''returns 0 then, it means the '''user '''does not exist in the system. | | So, if the '''method '''returns 0 then, it means the '''user '''does not exist in the system. | ||
|- | |- | ||
− | | 05 | + | | 05:42 |
| ''' else''', If user exists then we call '''bookAlreadyIssued method.''' | | ''' else''', If user exists then we call '''bookAlreadyIssued method.''' | ||
|- | |- | ||
− | | 05 | + | | 05:50 |
| We then store the returned value of the '''method '''in '''bookIssued.''' | | We then store the returned value of the '''method '''in '''bookIssued.''' | ||
|- | |- | ||
− | | 05 | + | | 05:55 |
| Here, we check if the same '''book '''has already been issued by the same''' user'''. | | Here, we check if the same '''book '''has already been issued by the same''' user'''. | ||
|- | |- | ||
− | | 06 | + | | 06:01 |
| Now, let us come to '''bookAlreadyIssued method.''' | | Now, let us come to '''bookAlreadyIssued method.''' | ||
|- | |- | ||
− | | 06 | + | | 06:05 |
| Here, we have set an '''integer variable bookAlreadyIssued '''to '''0.''' | | Here, we have set an '''integer variable bookAlreadyIssued '''to '''0.''' | ||
|- | |- | ||
− | |06 | + | |06:12 |
| We execute the query to check if a '''book '''with the same '''bookid '''is issued by the same '''user.''' | | We execute the query to check if a '''book '''with the same '''bookid '''is issued by the same '''user.''' | ||
|- | |- | ||
− | | 06 | + | | 06:18 |
| We get '''bookid '''from '''Checkout '''table. | | We get '''bookid '''from '''Checkout '''table. | ||
|- | |- | ||
− | | 06 | + | | 06:23 |
| If '''BookId '''exists then, set the variable '''bookAlreadyIssued '''to '''1.''' | | If '''BookId '''exists then, set the variable '''bookAlreadyIssued '''to '''1.''' | ||
|- | |- | ||
− | | 06 | + | | 06:30 |
| We then return the value of '''bookAlreadyIssued.''' | | We then return the value of '''bookAlreadyIssued.''' | ||
|- | |- | ||
− | | 06 | + | | 06:34 |
| So, If the '''method '''returns '''1 '''then it means the same user has already borrowed this book. | | So, If the '''method '''returns '''1 '''then it means the same user has already borrowed this book. | ||
|- | |- | ||
− | |06 | + | |06:43 |
|Now, come back to the '''browser.''' | |Now, come back to the '''browser.''' | ||
|- | |- | ||
− | | 06 | + | | 06:46 |
| Now, Let us now try to '''checkout '''the same book by the same '''user.''' | | Now, Let us now try to '''checkout '''the same book by the same '''user.''' | ||
|- | |- | ||
− | | 06 | + | | 06:51 |
|Type the '''username '''as '''arya.''' | |Type the '''username '''as '''arya.''' | ||
|- | |- | ||
− | | 06 | + | | 06:54 |
|Click on the radio button against '''BookId 1.''' | |Click on the radio button against '''BookId 1.''' | ||
|- | |- | ||
− | | 06 | + | | 06:59 |
|Then click on '''Checkout book.''' | |Then click on '''Checkout book.''' | ||
|- | |- | ||
− | | 07 | + | | 07:03 |
| We see that we get '''error message '''that''' the same user has already borrowed this book.''' | | We see that we get '''error message '''that''' the same user has already borrowed this book.''' | ||
|- | |- | ||
− | | 07 | + | | 07:10 |
| Now, switch back to the '''IDE.''' | | Now, switch back to the '''IDE.''' | ||
|- | |- | ||
− | | 07 | + | | 07:14 |
| If '''userExists '''in the system and if the '''checkout_book '''is not '''null, '''we call '''checkout method.''' | | If '''userExists '''in the system and if the '''checkout_book '''is not '''null, '''we call '''checkout method.''' | ||
|- | |- | ||
− | | 07 | + | | 07:22 |
|Let us see what we do in this '''method.''' | |Let us see what we do in this '''method.''' | ||
|- | |- | ||
− | | 07 | + | | 07:25 |
|Here, we get the '''availablecopies '''for corresponding '''id.''' | |Here, we get the '''availablecopies '''for corresponding '''id.''' | ||
|- | |- | ||
− | | 07 | + | | 07:31 |
| We get this from '''Books table.''' | | We get this from '''Books table.''' | ||
|- | |- | ||
− | | 07 | + | | 07:35 |
| We then store the number of availablecopies into the '''variable''' '''availableCopies.''' | | We then store the number of availablecopies into the '''variable''' '''availableCopies.''' | ||
|- | |- | ||
− | | 07 | + | | 07:41 |
| We check if '''availableCopies '''is greater than '''0 '''and '''bookIssued '''''is equal to '''''0.''' | | We check if '''availableCopies '''is greater than '''0 '''and '''bookIssued '''''is equal to '''''0.''' | ||
|- | |- | ||
− | | 07 | + | | 07:50 |
| We get the '''dateofreturn '''from the '''request '''and store in the '''returndate.''' | | We get the '''dateofreturn '''from the '''request '''and store in the '''returndate.''' | ||
|- | |- | ||
− | |07 | + | |07:56 |
| We then, call '''insertIntoCheckout.''' | | We then, call '''insertIntoCheckout.''' | ||
|- | |- | ||
− | | 08 | + | | 08:00 |
| We will see what we do in '''insertIntoCheckout method.''' | | We will see what we do in '''insertIntoCheckout method.''' | ||
|- | |- | ||
− | | 08 | + | | 08:05 |
| Here, we store the '''book_id, userName and returndate '''into the '''Checkout table.''' | | Here, we store the '''book_id, userName and returndate '''into the '''Checkout table.''' | ||
|- | |- | ||
− | | 08 | + | | 08:12 |
| Then we call '''decrementAvailableCopies method.''' | | Then we call '''decrementAvailableCopies method.''' | ||
|- | |- | ||
− | | 08 | + | | 08:16 |
| We will see what we do in this '''method.''' | | We will see what we do in this '''method.''' | ||
|- | |- | ||
− | | 08 | + | | 08:19 |
| Here, we execute the query to decrement the '''availablecopies '''in the''' Books table '''by '''1. ''' | | Here, we execute the query to decrement the '''availablecopies '''in the''' Books table '''by '''1. ''' | ||
|- | |- | ||
− | | 08 | + | | 08:26 |
| Then we call the '''setCheckoutIntoRequest method.''' | | Then we call the '''setCheckoutIntoRequest method.''' | ||
|- | |- | ||
− | | 08 | + | | 08:29 |
| Let us come to this method. | | Let us come to this method. | ||
|- | |- | ||
− | | 08 | + | | 08:32 |
| In this method, we set the '''checkout attribute '''into the '''request.''' | | In this method, we set the '''checkout attribute '''into the '''request.''' | ||
|- | |- | ||
− | | 08 | + | | 08:38 |
| Then we we forward the '''request '''to '''successCheckout.jsp '''using '''RequestDispatcher.''' | | Then we we forward the '''request '''to '''successCheckout.jsp '''using '''RequestDispatcher.''' | ||
|- | |- | ||
− | | 08 | + | | 08:45 |
| If '''availableCopies '''is '''0, '''then we print '''There are no copies of the requested book available.''' | | If '''availableCopies '''is '''0, '''then we print '''There are no copies of the requested book available.''' | ||
|- | |- | ||
− | | 08 | + | | 08:53 |
| Now, let us come to '''successCheckout '''''dot '''''jsp.''' | | Now, let us come to '''successCheckout '''''dot '''''jsp.''' | ||
|- | |- | ||
− | | 08 | + | | 08:58 |
| Here, first we get the '''checkout attribute '''from the '''request.''' | | Here, first we get the '''checkout attribute '''from the '''request.''' | ||
|- | |- | ||
− | | 09 | + | | 09:03 |
| We then, display the success message for successful '''Checkout.''' | | We then, display the success message for successful '''Checkout.''' | ||
|- | |- | ||
− | | 09 | + | | 09:08 |
| You can try out the different errors by yourself. | | You can try out the different errors by yourself. | ||
|- | |- | ||
− | | 09 | + | | 09:11 |
| Now, let us return the book. So switch to the '''browser''' | | Now, let us return the book. So switch to the '''browser''' | ||
|- | |- | ||
− | | 09 | + | | 09:15 |
| Click on '''bookId 1 '''and type the username as '''arya.''' | | Click on '''bookId 1 '''and type the username as '''arya.''' | ||
|- | |- | ||
− | | 09 | + | | 09:21 |
| Then, click on '''Return book.''' | | Then, click on '''Return book.''' | ||
|- | |- | ||
− | | 09 | + | | 09:24 |
| We get the success message that book has been successfully returned. | | We get the success message that book has been successfully returned. | ||
|- | |- | ||
− | | 09 | + | | 09:29 |
| Click on '''here '''for another '''checkout/return.''' | | Click on '''here '''for another '''checkout/return.''' | ||
|- | |- | ||
− | | 09 | + | | 09:33 |
| So, we come back to '''Admin Section Page.''' | | So, we come back to '''Admin Section Page.''' | ||
|- | |- | ||
− | | 09 | + | | 09:36 |
| Click on '''Checkout/Return Book.''' | | Click on '''Checkout/Return Book.''' | ||
|- | |- | ||
− | | 09 | + | | 09:39 |
| We can see that the number of available copies has been incremented. | | We can see that the number of available copies has been incremented. | ||
|- | |- | ||
− | | 09 | + | | 09:45 |
| We will see the code for this. | | We will see the code for this. | ||
|- | |- | ||
− | | 09 | + | | 09:47 |
|Come back to the '''IDE.''' | |Come back to the '''IDE.''' | ||
|- | |- | ||
− | | 09 | + | | 09:49 |
| Open '''CheckoutServlet '''''dot '''''java.''' | | Open '''CheckoutServlet '''''dot '''''java.''' | ||
|- | |- | ||
− | | 09 | + | | 09:53 |
| We check if '''userExists '''''is equal to '''''1 '''and '''return_book '''''is not equal to '''''null.''' | | We check if '''userExists '''''is equal to '''''1 '''and '''return_book '''''is not equal to '''''null.''' | ||
|- | |- | ||
− | | 10 | + | | 10:00 |
| Then we call '''returnBook method.''' | | Then we call '''returnBook method.''' | ||
|- | |- | ||
− | | 10 | + | | 10:03 |
| Let us come to this method. | | Let us come to this method. | ||
|- | |- | ||
− | | 10 | + | | 10:06 |
| Here, we select the '''totalcopies '''and '''availablecopies '''from '''Books''' table for the '''book id.''' | | Here, we select the '''totalcopies '''and '''availablecopies '''from '''Books''' table for the '''book id.''' | ||
|- | |- | ||
− | | 10 | + | | 10:14 |
| We store the '''totalcopies '''and '''availablecopies '''to '''totcopies '''and '''availcopies.''' | | We store the '''totalcopies '''and '''availablecopies '''to '''totcopies '''and '''availcopies.''' | ||
|- | |- | ||
− | | 10 | + | | 10:21 |
| Then we check if '''available copies '''exceed the '''totalcopies.''' | | Then we check if '''available copies '''exceed the '''totalcopies.''' | ||
|- | |- | ||
− | | 10 | + | | 10:27 |
| Let us come back to the browser. | | Let us come back to the browser. | ||
|- | |- | ||
− | | 10 | + | | 10:30 |
| Let us now return a book for a '''user '''who has not borrowed the '''book.''' | | Let us now return a book for a '''user '''who has not borrowed the '''book.''' | ||
|- | |- | ||
− | | 10 | + | | 10:35 |
| Type the username as '''mdhusein.''' | | Type the username as '''mdhusein.''' | ||
|- | |- | ||
− | | 10 | + | | 10:39 |
| Click on '''book id 1.''' | | Click on '''book id 1.''' | ||
|- | |- | ||
− | | 10 | + | | 10:42 |
| Then click on '''Return Book.''' | | Then click on '''Return Book.''' | ||
|- | |- | ||
− | | 10 | + | | 10:44 |
| We can see that we get the '''error message''' '''The given user has not borrowed this book!!''' | | We can see that we get the '''error message''' '''The given user has not borrowed this book!!''' | ||
|- | |- | ||
− | | 10 | + | | 10:50 |
| Now, come back to the '''IDE.''' | | Now, come back to the '''IDE.''' | ||
|- | |- | ||
− | | 10 | + | | 10:53 |
| Here, we check if '''bookIssued''' is equal to '''1.''' | | Here, we check if '''bookIssued''' is equal to '''1.''' | ||
|- | |- | ||
− | | 10 | + | | 10:57 |
| We then call '''removeFromCheckout method.''' | | We then call '''removeFromCheckout method.''' | ||
|- | |- | ||
− | | 11 | + | | 11:01 |
| Let us come to this method. | | Let us come to this method. | ||
|- | |- | ||
− | | 11 | + | | 11:04 |
| Here, we execute the query to delete from '''Checkout table '''the entry which has returned the book. | | Here, we execute the query to delete from '''Checkout table '''the entry which has returned the book. | ||
|- | |- | ||
− | | 11 | + | | 11:14 |
| Then, we call '''incrementAvailableCopies method.''' | | Then, we call '''incrementAvailableCopies method.''' | ||
|- | |- | ||
− | | 11 | + | | 11:18 |
| Let us come to this method. | | Let us come to this method. | ||
|- | |- | ||
− | | 11 | + | | 11:21 |
|Here, we increment the '''availablecopies '''by 1. | |Here, we increment the '''availablecopies '''by 1. | ||
|- | |- | ||
− | | 11 | + | | 11:25 |
| We execute the query to update in the '''Books table.''' | | We execute the query to update in the '''Books table.''' | ||
|- | |- | ||
− | | 11 | + | | 11:29 |
| Then we call the '''setReturnIntoRequest method.''' | | Then we call the '''setReturnIntoRequest method.''' | ||
|- | |- | ||
− | | 11 | + | | 11:34 |
| Let us come to this '''method.''' | | Let us come to this '''method.''' | ||
|- | |- | ||
− | | 11 | + | | 11:37 |
| Here, we set the '''returnBook attribute '''into the '''request.''' | | Here, we set the '''returnBook attribute '''into the '''request.''' | ||
|- | |- | ||
− | | 11 | + | | 11:41 |
| Then we forward to '''successReturn page '''using '''RequestDispatcher.''' | | Then we forward to '''successReturn page '''using '''RequestDispatcher.''' | ||
|- | |- | ||
− | | 11 | + | | 11:48 |
| The '''successReturn page '''is similar to that we had for '''successCheckout page.''' | | The '''successReturn page '''is similar to that we had for '''successCheckout page.''' | ||
|- | |- | ||
− | | 11 | + | | 11:53 |
| Now, come back to the browser. Come back to the login page. | | Now, come back to the browser. Come back to the login page. | ||
|- | |- | ||
− | | 11 | + | | 11:58 |
| We can see that we have a link called '''Visitor’s Home Page. ''' | | We can see that we have a link called '''Visitor’s Home Page. ''' | ||
|- | |- | ||
− | | 12 | + | | 12:03 |
| We can see that we get a list of all the books available. | | We can see that we get a list of all the books available. | ||
|- | |- | ||
− | |12 | + | |12:07 |
| So, In this tutorial we have learnt: | | So, In this tutorial we have learnt: | ||
|- | |- | ||
− | | 12 | + | | 12:10 |
| To list all the users | | To list all the users | ||
|- | |- | ||
− | | 12 | + | | 12:12 |
| To fetch a book | | To fetch a book | ||
|- | |- | ||
− | | 12 | + | | 12:13 |
| To return a book. | | To return a book. | ||
|- | |- | ||
− | | 12 | + | | 12:15 |
| To know more about spoken tutorial project, watch the video available at the following link. | | To know more about spoken tutorial project, watch the video available at the following link. | ||
|- | |- | ||
− | | 12 | + | | 12:20 |
| It summarizes the Spoken Tutorial Project | | It summarizes the Spoken Tutorial Project | ||
|- | |- | ||
− | | 12 | + | | 12:24 |
| If you do not have good bandwidth you can download and watch it | | If you do not have good bandwidth you can download and watch it | ||
|- | |- | ||
− | | 12 | + | | 12:28 |
| The Spoken Tutorial Project Team | | The Spoken Tutorial Project Team | ||
|- | |- | ||
− | | 12 | + | | 12:30 |
| Conducts workshops using spoken tutorials | | Conducts workshops using spoken tutorials | ||
|- | |- | ||
− | | 12 | + | | 12:32 |
| Gives certificates to those who pass an online test | | Gives certificates to those who pass an online test | ||
|- | |- | ||
− | | 12 | + | | 12:36 |
| For more details please write to contact at spoken hyphen tutorial dot org | | For more details please write to contact at spoken hyphen tutorial dot org | ||
|- | |- | ||
− | |12 | + | |12:41 |
| Spoken Tutorial Project is a part of the Talk to a Teacher Project | | Spoken Tutorial Project is a part of the Talk to a Teacher Project | ||
|- | |- | ||
− | | 12 | + | | 12:44 |
| It is supported by the National Mission on Education through ICT, MHRD, Government of India | | It is supported by the National Mission on Education through ICT, MHRD, Government of India | ||
|- | |- | ||
− | | 12 | + | | 12:50 |
| More information on this mission is available at | | More information on this mission is available at | ||
|- | |- | ||
− | | 12 | + | | 12:52 |
| http://spoken-tutorial.org/NMEICT-Intro | | http://spoken-tutorial.org/NMEICT-Intro | ||
|- | |- | ||
− | | 12 | + | | 12:58 |
| The Library Management System has been contributed by a leading software MNC, through their Corporate Social Responsibility Programme. | | The Library Management System has been contributed by a leading software MNC, through their Corporate Social Responsibility Programme. | ||
|- | |- | ||
− | | 13 | + | | 13:06 |
| They have also validated the content for this spoken tutorial. | | They have also validated the content for this spoken tutorial. | ||
|- | |- | ||
− | | 13 | + | | 13:10 |
| This is Arya Ratish from IIT Bombay signing off. Thank you for joining. | | This is Arya Ratish from IIT Bombay signing off. Thank you for joining. | ||
|} | |} |
Revision as of 17:20, 19 September 2014
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. |