Difference between revisions of "Java-Business-Application/C2/Issuing-and-Returning-a-book/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
 
(18 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
+
{| border = 1
{| border-spacing = 1
+
| '''Time'''
| | Time
+
| '''Narration'''
| | Narration
+
  
 
|-
 
|-
| 00.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.05
+
| 00:05
| In this tutorial, we will learn how to :
+
| In this tutorial, we will learn how:
  
 
|-
 
|-
| 00.08
+
| 00:08
| Fetch all the user details
+
|To fetch all the user details
  
 
|-
 
|-
| 00.11
+
| 00:11
| To Issue a book
+
|To issue a book
  
 
|-
 
|-
| 00.13
+
| 00:13
| To return a book
+
|To return a book.
  
 
|-
 
|-
| 00.15
+
| 00:15
| Here we are using
+
| Here we are using:
  
 
|-
 
|-
| 00.17
+
| 00:17
| Ubuntu Version 12.04
+
|'''Ubuntu''' Version '''12.04'''
  
 
|-
 
|-
| 00.20
+
| 00:20
| Netbeans IDE 7.3
+
|'''Netbeans IDE 7.3'''
  
 
|-
 
|-
| 00.23
+
| 00:23
| JDK 1.7
+
| '''JDK 1.7'''
  
 
|-
 
|-
| 00.25
+
| 00:25
| Firefox web-browser 21.0
+
| '''Firefox''' web-browser '''21.0'''
  
 
|-
 
|-
| 00.29
+
| 00:29
 
| You can use any web-browser of your choice.
 
| You can use any web-browser of your choice.
  
 
|-
 
|-
| 00.33
+
| 00:33
| To follow this tutorial you must have knowledge of
+
| To follow this tutorial, you must have knowledge of:
  
 
|-
 
|-
| 00.37
+
| 00:37
 
| Basics of '''Java Servlets '''and '''JSPs'''
 
| Basics of '''Java Servlets '''and '''JSPs'''
  
 
|-
 
|-
| 00.40
+
| 00:40
| Creating and viewing inventories  
+
| Creating and viewing inventories.
  
 
|-
 
|-
| 00.44
+
| 00:44
 
| If not, for relevant tutorials please visit our website.
 
| If not, for relevant tutorials please visit our website.
  
 
|-
 
|-
| 00.48
+
| 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.53
+
| 00:53
| Here, in this tutorial we have added more functionalities to the '''Admin Section.'''
+
| Here, in this tutorial, we have added more functionality to the '''Admin Section.'''
  
 
|-
 
|-
| 00.59
+
| 00:59
|  So, Let us switch to the '''browser.'''
+
|  So, let us switch to the '''browser.'''
  
 
|-
 
|-
| 01.02
+
| 01:02
|  Let us login again as the '''admin.'''
+
|  Let us '''login''' again as the '''admin.'''
  
 
|-
 
|-
| 01.05
+
| 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.14
+
| 01:14
 
|  Now, let us come to the '''IDE. '''
 
|  Now, let us come to the '''IDE. '''
  
 
|-
 
|-
| 01.18
+
| 01:18
| We can see that in the '''adminsetion.jsp''' there are two more '''radio buttons.'''
+
| We can see that in the '''adminsection.jsp''' there are two more '''radio buttons.'''
  
 
|-
 
|-
| 01.24
+
| 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.30
+
| 01:30
|Now, switch back to the '''browser.'''
+
|Now, switch back to the browser.
  
 
|-
 
|-
| 01.33
+
| 01:33
 
| We will click on the '''radio button '''for '''List Users.'''  
 
| We will click on the '''radio button '''for '''List Users.'''  
  
 
|-
 
|-
|01.38
+
|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.48
+
| 01:48
|The steps are similar to the earlier two options.
+
|The steps are similar to the earlier two options;
  
 
|-
 
|-
| 01.51
+
| 01:51
| We saw them in the previous tutorial.
+
| we saw them in the previous tutorial.
  
 
|-
 
|-
| 01.55
+
| 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.01
+
| 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.06
+
| 02:06
 
| We will now see the code for the same.
 
| We will now see the code for the same.
  
 
|-
 
|-
| 02.09
+
| 02:09
 
| Switch back to the '''IDE.'''
 
| Switch back to the '''IDE.'''
  
 
|-
 
|-
| 02.11
+
| 02:11
 
| We clicked on '''Checkout/Return Book.'''
 
| We clicked on '''Checkout/Return Book.'''
  
 
|-
 
|-
| 02.14
+
| 02:14
| So '''menuselection '''is equal to '''checkoutbook'''
+
| So '''menuSelection '''is equal to '''checkoutbook'''.
  
 
|-
 
|-
| 02.18
+
| 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.23
+
| 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.29
+
| 02:29
| Now, let us come to '''checkOut '''''dot '''''jsp.'''
+
| Now, let us come to '''checkOut ''' dot '''jsp.'''
  
 
|-
 
|-
| 02.33
+
| 02:33
| This page is similar to that of '''listBooks '''''dot '''''jsp.'''
+
| This page is similar to that of '''listBooks''' dot '''jsp'''
  
 
|-
 
|-
| 02.38
+
| 02:38
| Except that we have a '''radio button '''against each '''book.'''
+
| except that we have a '''radio button '''against each '''book'''
  
 
|-
 
|-
| 02.42
+
| 02:42
| So that we can '''Checkout/Return ''' that '''book.'''
+
| so that we can '''Checkout/Return ''' that '''book.'''
  
 
|-
 
|-
| 02.46
+
| 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 '''User name''' field to get the '''username '''of the '''user '''who has to '''checkout''' the book.
  
 
|-
 
|-
| 02.53
+
| 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.59
+
| 02:59
| We set the return date as one week from current date.
+
| We have set the return date as one week from current date.
  
 
|-
 
|-
| 03.04
+
| 03:04
| This is done using the class '''Calendar.'''
+
| This is done using the '''class''' '''Calendar.'''
  
 
|-
 
|-
| 03.07
+
| 03:07
| The add function of this class takes two parameters.
+
| The '''add()''' '''function''' of this '''class''' takes two '''parameters'''.
  
 
|-
 
|-
| 03.13
+
| 03:13
| The First is the present day of the year.
+
| The first is the present day of the year.
  
 
|-
 
|-
| 03.16
+
| 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.21
+
| 03:21
 
| We have added seven days.
 
| We have added seven days.
  
 
|-
 
|-
| 03.23
+
| 03:23
| Now note that  '''form action '''is equal to '''CheckoutServlet.'''
+
| Now, note that  '''form action '''is equal to '''CheckOutServlet.'''
  
 
|-
 
|-
| 03.29
+
| 03:29
| Now, let us come back to the '''browser.'''
+
| Now, let us come back to the browser.
  
 
|-
 
|-
| 03.32
+
| 03:32
| We will now click on '''BookId 1.'''
+
| We will click on '''Book Id 1.'''
  
 
|-
 
|-
| 03.35
+
| 03:35
| Type the '''username '''as '''arya. '''
+
| Type the '''username '''as '''arya.'''
  
 
|-
 
|-
| 03.38
+
| 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.43
+
| 03:43
 
| Note that the number of '''Available Copies '''is '''9.'''
 
| Note that the number of '''Available Copies '''is '''9.'''
  
 
|-
 
|-
| 03.48
+
| 03:48
| Click on '''Checkout Book.'''
+
| Click on '''Checkout book.'''
  
 
|-
 
|-
| 03.51
+
| 03:51
 
| We get the '''Checkout Success Page.'''
 
| We get the '''Checkout Success Page.'''
  
 
|-
 
|-
| 03.55
+
| 03:55
| We will click on '''here '''to come back to '''Admin Section Page.'''
+
| We will click on '''here '''to come to the '''Admin Section Page.'''
  
 
|-
 
|-
| 03.59
+
| 03:59
 
| Again click on '''Checkout/Return Book.'''
 
| Again click on '''Checkout/Return Book.'''
  
 
|-
 
|-
| 04.03
+
| 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.08
+
| 04:08
 
|We will see the code for this now.
 
|We will see the code for this now.
  
 
|-
 
|-
| 04.10
+
| 04:10
 
| Come back to the '''IDE.'''
 
| Come back to the '''IDE.'''
  
 
|-
 
|-
| 04.13
+
| 04:13
| Go to '''CheckoutServlet.java.'''
+
| Go to '''CheckOutServlet.java.'''
  
 
|-
 
|-
| 04.16
+
| 04:16
|We have set the '''errorMsgs''' list
+
|We have set the '''errorMsgs''' list.
 
+
  
 
|-
 
|-
| 04.19
+
| 04:19
 
|We have set the '''errorMsgs '''in the '''request.'''
 
|We have set the '''errorMsgs '''in the '''request.'''
  
 
|-
 
|-
| 04.23
+
| 04:23
 
| We get the '''username '''from the '''request using getParameter.'''
 
| We get the '''username '''from the '''request using getParameter.'''
  
 
|-
 
|-
| 04.28
+
| 04:28
| Similarly we get  '''checkout_book, return_book '''and '''book id.'''
+
| Similarly, we get  '''checkout_book, return_book '''and '''book-id.'''
  
 
|-
 
|-
| 04.34
+
| 04:34
| Next, we parse the '''BookId '''as '''Integer '''from the '''Id.'''
+
| Next, we parse the '''book_id '''as '''Integer '''from the '''id.'''
  
 
|-
 
|-
| 04.40
+
| 04:40
| We validate the '''username '''and '''book id.'''
+
| We validate the '''userName '''and '''book id.'''
  
 
|-
 
|-
| 04.44
+
| 04:44
|  We also validate if '''Checkout_book '''and '''Return_Book '''is '''null.'''
+
|  We also validate if '''Checkout_book '''and '''Return_Book '''are '''null'''.
  
 
|-
 
|-
| 04.50
+
| 04:50
|Then, we validate if either of them is not '''null.'''
+
|Then, we validate if either of them is not '''null'''.
  
 
|-
 
|-
| 04.55
+
| 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.01
+
| 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.07
+
| 05:07
 
| Now, we will see what we do in this '''method.'''
 
| Now, we will see what we do in this '''method.'''
  
 
|-
 
|-
|05.11
+
|05:11
|First we execute the query to check if the '''username '''exists in the '''table.'''
+
|Here, first we execute the '''query''' to check if the '''username '''exists in the '''table.'''
  
 
|-
 
|-
| 05.18
+
| 05:18
 
| Then we initialize the '''integer variable''' '''userExists '''to '''0.'''
 
| Then we initialize the '''integer variable''' '''userExists '''to '''0.'''
  
 
|-
 
|-
| 05.23
+
| 05:23
 
| If the '''username '''exists then we set '''userExists '''to '''1.'''
 
| If the '''username '''exists then we set '''userExists '''to '''1.'''
  
 
|-
 
|-
| 05.29
+
| 05:29
 
| We then return the value of '''userExists.'''
 
| We then return the value of '''userExists.'''
  
 
|-
 
|-
| 05.33
+
| 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.42
+
| 05:42
| ''' else''', If user exists then we call  '''bookAlreadyIssued method.'''
+
| else, if user exists then we call  ''''bookAlreadyIssued' method.'''
  
 
|-
 
|-
| 05.50
+
| 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.55
+
| 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.01
+
|  06:01
 
| Now, let us come to '''bookAlreadyIssued method.'''
 
| Now, let us come to '''bookAlreadyIssued method.'''
  
 
|-
 
|-
| 06.05
+
| 06:05
 
| Here, we have set an '''integer variable bookAlreadyIssued '''to '''0.'''
 
| Here, we have set an '''integer variable bookAlreadyIssued '''to '''0.'''
  
 
|-
 
|-
|06.12
+
|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 '''book_id '''is issued by the same '''user.'''
  
 
|-
 
|-
| 06.18
+
| 06:18
| We get '''bookid '''from '''Checkout '''table.
+
| We get the '''book_id '''from '''Checkout '''table.
  
 
|-
 
|-
| 06.23
+
| 06:23
| If '''BookId '''exists then, set the variable '''bookAlreadyIssued '''to '''1.'''
+
| If '''BookId '''exists then set the variable '''bookAlreadyIssued '''to '''1.'''
  
 
|-
 
|-
| 06.30
+
| 06:30
| We then return the value of '''bookAlreadyIssued.'''
+
| We then '''return''' the value of '''bookAlreadyIssued.'''
  
 
|-
 
|-
| 06.34
+
| 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.43
+
|06:43
|Now, come back to the '''browser.'''
+
|Now, come back to the browser.
  
 
|-
 
|-
| 06.46
+
| 06:46
| Now, Let us now try to '''checkout '''the same book by the same '''user.'''
+
| Now, let us try to '''checkout '''the same book by the same '''user.'''
  
 
|-
 
|-
| 06.51
+
| 06:51
 
|Type the '''username '''as '''arya.'''
 
|Type the '''username '''as '''arya.'''
  
 
|-
 
|-
| 06.54
+
| 06:54
|Click on the radio button against '''BookId 1.'''
+
|Click on the radio button against '''Book Id 1.'''
  
 
|-
 
|-
| 06.59
+
| 06:59
 
|Then click on '''Checkout book.'''
 
|Then click on '''Checkout book.'''
  
 
|-
 
|-
| 07.03
+
| 07:03
|  We see that we get '''error message '''that''' the same user has already borrowed this book.'''
+
|  We see that we get the'''error message '''that''' "The same user has already borrowed this book".'''
  
 
|-
 
|-
| 07.10
+
| 07:10
 
| Now, switch back to the '''IDE.'''
 
| Now, switch back to the '''IDE.'''
  
 
|-
 
|-
| 07.14
+
| 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.22
+
| 07:22
 
|Let us see what we do in this '''method.'''
 
|Let us see what we do in this '''method.'''
  
 
|-
 
|-
| 07.25
+
| 07:25
|Here, we get the '''availablecopies '''for corresponding '''id.'''
+
|Here, we get the '''availablecopies '''for the corresponding '''id.'''
  
 
|-
 
|-
| 07.31
+
| 07:31
 
| We get this from  '''Books table.'''
 
| We get this from  '''Books table.'''
  
 
|-
 
|-
| 07.35
+
| 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.41
+
| 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.50
+
|  07:50
|  We get the '''dateofreturn '''from the '''request '''and store in the '''returndate.'''
+
|  We get the '''dateofreturn''' from the '''request '''and store it in '''returndate.'''
  
 
|-
 
|-
|07.56
+
|07:56
| We then, call  '''insertIntoCheckout.'''
+
| We then call  '''insertIntoCheckout.'''
  
 
|-
 
|-
|  08.00
+
|  08:00
 
| We will see what we do in '''insertIntoCheckout method.'''
 
| We will see what we do in '''insertIntoCheckout method.'''
  
 
|-
 
|-
| 08.05
+
| 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.12
+
| 08:12
 
| Then we call '''decrementAvailableCopies method.'''
 
| Then we call '''decrementAvailableCopies method.'''
  
 
|-
 
|-
| 08.16
+
| 08:16
 
| We will see what we do in this '''method.'''
 
| We will see what we do in this '''method.'''
  
 
|-
 
|-
| 08.19
+
| 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 '''Available Copies '''in the''' Books''' table by '''1. '''
  
 
|-
 
|-
| 08.26
+
| 08:26
 
|  Then we call the '''setCheckoutIntoRequest method.'''
 
|  Then we call the '''setCheckoutIntoRequest method.'''
  
 
|-
 
|-
| 08.29
+
| 08:29
| Let us come to this method.
+
| Let us come to this '''method'''.
  
 
|-
 
|-
| 08.32
+
| 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.38
+
| 08:38
|  Then we we forward the '''request '''to '''successCheckout.jsp '''using '''RequestDispatcher.'''
+
|  Then we forward the '''request '''to '''successCheckout.jsp '''using '''RequestDispatcher.'''
  
 
|-
 
|-
| 08.45
+
| 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.53
+
| 08:53
|  Now, let us come to '''successCheckout '''''dot '''''jsp.'''
+
|  Now, let us come to '''successCheckout ''' dot '''jsp.'''
  
 
|-
 
|-
| 08.58
+
| 08:58
 
|  Here, first we get the '''checkout attribute '''from the '''request.'''
 
|  Here, first we get the '''checkout attribute '''from the '''request.'''
  
 
|-
 
|-
| 09.03
+
| 09:03
| We then, display the success message for successful '''Checkout.'''
+
| We then display the success message for successful '''Checkout.'''
  
 
|-
 
|-
| 09.08
+
| 09:08
| You can try out the different errors by yourself.
+
| You can try out the different '''errors''' by yourself.
  
 
|-
 
|-
| 09.11
+
| 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.15
+
| 09:15
| Click on '''bookId 1 '''and type the username as '''arya.'''
+
| Click on '''Book Id 1 '''and type the username as "arya".
  
 
|-
 
|-
| 09.21
+
| 09:21
 
| Then, click on '''Return book.'''
 
| Then, click on '''Return book.'''
  
 
|-
 
|-
| 09.24
+
| 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.29
+
| 09:29
 
| Click on '''here '''for another '''checkout/return.'''
 
| Click on '''here '''for another '''checkout/return.'''
  
 
|-
 
|-
|  09.33
+
|  09:33
 
| So, we come back to  '''Admin Section Page.'''
 
| So, we come back to  '''Admin Section Page.'''
  
 
|-
 
|-
| 09.36
+
| 09:36
 
| Click on '''Checkout/Return Book.'''
 
| Click on '''Checkout/Return Book.'''
  
 
|-
 
|-
| 09.39
+
| 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.45
+
|  09:45
 
| We will see the code for this.
 
| We will see the code for this.
  
 
|-
 
|-
| 09.47
+
| 09:47
 
|Come back to the '''IDE.'''
 
|Come back to the '''IDE.'''
  
 
|-
 
|-
| 09.49
+
| 09:49
|  Open '''CheckoutServlet '''''dot '''''java.'''
+
|  Open '''CheckOutServlet ''' dot '''java.'''
  
 
|-
 
|-
| 09.53
+
| 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.00
+
| 10:00
 
|  Then we call '''returnBook method.'''
 
|  Then we call '''returnBook method.'''
  
 
|-
 
|-
|  10.03
+
|  10:03
| Let us come to this method.
+
| Let us come to this '''method'''.
  
 
|-
 
|-
| 10.06
+
| 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.14
+
| 10:14
| We store the '''totalcopies '''and '''availablecopies '''to '''totcopies '''and '''availcopies.'''
+
| We store the '''Total Copies '''and '''Available Copies '''to '''totcopies''' and '''availcopies.'''
  
 
|-
 
|-
| 10.21
+
| 10:21
| Then we check if '''available copies '''exceed the '''totalcopies.'''
+
| Then we check if '''available copies '''exceed the '''total Copies.'''
  
 
|-
 
|-
| 10.27
+
| 10:27
| Let us come back to the browser.
+
| Now, let us come back to the browser.
  
 
|-
 
|-
| 10.30
+
| 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.35
+
| 10:35
| Type the username as '''mdhusein.'''
+
| Type the '''User name''' as '''mdhusein.'''
  
 
|-
 
|-
| 10.39
+
| 10:39
| Click on  '''book id 1.'''
+
| Click on  '''Book Id 1.'''
  
 
|-
 
|-
| 10.42
+
| 10:42
| Then click on '''Return Book.'''
+
| Then click on '''Return book.'''
  
 
|-
 
|-
| 10.44
+
| 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.50
+
| 10:50
 
| Now, come back to the '''IDE.'''
 
| Now, come back to the '''IDE.'''
  
 
|-
 
|-
| 10.53
+
| 10:53
 
| Here, we check if  '''bookIssued''' is equal to '''1.'''
 
| Here, we check if  '''bookIssued''' is equal to '''1.'''
  
 
|-
 
|-
| 10.57
+
| 10:57
 
| We then call  '''removeFromCheckout method.'''
 
| We then call  '''removeFromCheckout method.'''
  
 
|-
 
|-
|  11.01
+
|  11:01
| Let us come to this method.
+
| Let us come to this '''method'''.
  
 
|-
 
|-
| 11.04
+
| 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.14
+
| 11:14
 
| Then, we call  '''incrementAvailableCopies method.'''
 
| Then, we call  '''incrementAvailableCopies method.'''
  
 
|-
 
|-
| 11.18
+
| 11:18
| Let us come to this method.
+
| Let us come to this '''method'''.
  
 
|-
 
|-
| 11.21
+
| 11:21
|Here, we increment the '''availablecopies '''by 1.
+
|Here, we increment the '''Available Copies '''by 1.
  
 
|-
 
|-
| 11.25
+
| 11:25
| We execute the query to update in the '''Books table.'''
+
| We '''execute''' the '''query''' to update in the '''Books table.'''
  
 
|-
 
|-
| 11.29
+
| 11:29
 
| Then we call the '''setReturnIntoRequest method.'''
 
| Then we call the '''setReturnIntoRequest method.'''
  
 
|-
 
|-
| 11.34
+
| 11:34
 
| Let us come to this '''method.'''
 
| Let us come to this '''method.'''
  
 
|-
 
|-
| 11.37
+
| 11:37
 
| Here, we set the '''returnBook attribute '''into the '''request.'''
 
| Here, we set the '''returnBook attribute '''into the '''request.'''
  
 
|-
 
|-
| 11.41
+
| 11:41
 
| Then we forward to  '''successReturn page '''using  '''RequestDispatcher.'''
 
| Then we forward to  '''successReturn page '''using  '''RequestDispatcher.'''
  
 
|-
 
|-
| 11.48
+
| 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.53
+
| 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.58
+
| 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.03
+
| 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.07
+
|12:07
| So, In this tutorial we have learnt:
+
| So, in this tutorial, we have learnt:
  
 
|-
 
|-
| 12.10
+
| 12:10
| To list all the users
+
|To list all the users
  
 
|-
 
|-
| 12.12
+
|12:12
| To fetch a book
+
|To fetch a book and To return a book.
  
 
|-
 
|-
| 12.13
+
|12:15
| To return a book.
+
|To know more about the '''spoken tutorial''' project, watch the video available at the following link.
  
 
|-
 
|-
| 12.15
+
| 12:20
| To know more about spoken tutorial project, watch the video available at the following link.
+
| It summarizes the Spoken Tutorial Project.
  
 
|-
 
|-
| 12.20
+
| 12:24
It summarizes the Spoken Tutorial Project
+
If you do not have good bandwidth, you can download and watch it.
  
 
|-
 
|-
| 12.24
+
| 12:28
| If you do not have good bandwidth you can download and watch it
+
| The Spoken Tutorial Project Team:
  
 
|-
 
|-
| 12.28
+
| 12:30
| The Spoken Tutorial Project Team
+
| Conducts workshops using spoken tutorials.
  
 
|-
 
|-
| 12.30
+
| 12:32
Conducts workshops using spoken tutorials
+
Gives certificates to those who pass an online test.
  
 
|-
 
|-
| 12.32
+
| 12:36
Gives certificates to those who pass an online test
+
For more details, please write to contact at spoken hyphen tutorial dot org.
  
 
|-
 
|-
| 12.36
+
|12:41
| For more details please write to contact at spoken hyphen tutorial dot org
+
| Spoken Tutorial Project is a part of the "Talk to a Teacher" Project.
  
 
|-
 
|-
|12.41
+
| 12:44
| Spoken Tutorial Project is a part of the Talk to a Teacher Project
+
| It is supported by the National Mission on Education through ICT, MHRD, Government of India.
  
 
|-
 
|-
| 12.44
+
| 12:50
| It is supported by the National Mission on Education through ICT, MHRD, Government of India
+
|  More information on this mission is available at:
|-
+
| 12.50
+
|  More information on this mission is available at
+
  
 
|-
 
|-
| 12.52
+
| 12:52
 
|  http://spoken-tutorial.org/NMEICT-Intro
 
|  http://spoken-tutorial.org/NMEICT-Intro
  
 
|-
 
|-
| 12.58
+
| 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.06
+
| 13:06
 
| They have also validated the content for this spoken tutorial.
 
| They have also validated the content for this spoken tutorial.
  
 
|-
 
|-
| 13.10
+
| 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.
  
 
|}
 
|}

Latest revision as of 17:04, 9 March 2017

Time Narration
00:00 Welcome to the spoken-tutorial on Issuing and returning a book.
00:05 In this tutorial, we will learn how:
00:08 To 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 functionality 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 adminsection.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 User name 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 have 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 click on Book Id 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 to the 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 book_id 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 are 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 Here, 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 book_id is issued by the same user.
06:18 We get the book_id 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 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 Book Id 1.
06:59 Then click on Checkout book.
07:03 We see that we get theerror 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 the 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 it in 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 Available Copies 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 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 Book Id 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 Total Copies and Available Copies to totcopies and availcopies.
10:21 Then we check if available copies exceed the total Copies.
10:27 Now, 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 User name 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 Available Copies 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 and To return a book.
12:15 To know more about the 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.

Contributors and Content Editors

PoojaMoolya, Pratik kamble, Sandhya.np14