Welcome to the spoken-tutorial on Creating and viewing inventories.
In this tutorial, we will learn:
To modify the login page to redirect to admin page
To fetch all the book details
To fetch borrowed book details
To display the books borrowed by a logged in user.
Here we are using:
Ubuntu Version 12.04
Netbeans IDE 7.3
JDK 1.7
Firefox web-browser 21.0
You can use any web-browser of your choice.
To follow this tutorial, you must have knowledge of:
Basics of Java Servlets and JSPs
Database and validation of fields.
If not, for relevant tutorials please visit our website.
Now, let us switch to NetBeans IDE .
I have created the Books table.
You can see the different fields in the table.
I have inserted 10 books into this table.
I have created Checkout table to store borrowed books.
I have inserted 5 entries into the Checkout table.
I have also created a model for Book and Checkout.
Book.java is a book model.
And Checkout.java is a checkout model.
Now, come to the browser.
Let us login as the admin.
So, I will type the username and password as admin. Then click on Sign In.
We can see that we come to the Admin Section Page.
We will come back to this page. Now let us switch to Netbeans IDE.
We will see, how we modified the GreetingServlet to redirect to Admin Page.
Let us see the GreetingServlet.java.
Here we check if username and password equal admin.
If yes, then we redirect to adminsection.jsp.
We have already seen how to forward to another page using RequestDispatcher.
Now, switch back to the browser.
We have two options here.
We will click on the radio button for List Books.
Then click on Submit button.
Here, we can see that we have the list of all the Books.
It has all the details like- Book Id, Book Name, Author Name, ISBN, Publisher, Total Copies and Available copies.
Now, I will show you how this is done.
Switch back to the IDE.
Now, let us come to adminsection dot jsp.
Here we have two radio buttons.
The first one is to list all the books.
We can see that in adminsection dot jsp, we have form action equal to AdminSection.
Now, Open AdminSection dot java.
Here, this checks the option that we click on.
We clicked on List Books.
So, this part of the query will be executed.
We execute the query to fetch books from Books table.
Next, we create ArrayList to store the details of the books.
Then we iterate through the result set.
We create the Book object.
We set BookId into the Book object.
Similarly, we set other attributes of the book into the Book object.
Then we add book object into the books list.
Then we set the ArrayList books into the request.
Then we forward the request to listBooks.jsp using RequestDispatcher.
Now, we come to listBooks.jsp.
In this page, admin can view the list of books.
Here, first we obtain the books from the request.
This HTML table will display the details of the books.
So, we will iterate through the book list.
Here we display the BookId of the book.
Similarly, we display other attributes of the book.
This is how we display the list of books.
Now, switch back to the browser.
Click on List Borrowed Books.
And click on the Submit button.
We see a list of all the Books issued.
It has details like Transaction Id, Book Id and Username.
Now, I will switch back to the IDE
and show you the code for the same.
Go to AdminSection.java.
We had clicked on List Borrowed Books.
So menuSelection is equal to List Borrowed books.
The steps are similar to what we saw for List Books.
We execute the query to fetch borrowed books details from the Checkout table.
Then we iterate through the borrowed books
and set it into request as checkout attribute.
Now, we come to listBorrowedBooks.jsp.
Here we obtain checkout from the request.
We iterate through the Checkout list
and here we display the attributes of the Checkout.
This is how we display Borrowed Books.
Now, switch back to the browser.
In the borrowed books page, we have one more list.
The list of books issued when the current date is more than the return date.
Switch back to IDE to see the code.
This is done in the same way as we did for Borrowed Books.
The only difference is in the SQL query.
In the query, we give the condition: return_date less than now() order by transaction_Id.
Now, I will show you the interface for a normal user.
Switch back to the browser.
Come back to the login page.
I will login as mdhusein.
Type the password as welcome
and click on Sign In.
We get a Success Greeting Page.
It has the books currently borrowed by the user.
It has details like Transaction Id, User Name, Book Id and Return Date.
Now, let us come back to the IDE.
Now we go to GreetingServlet.java.
We display the books issued in the same way as we did for the admin.
Here the difference will be that we have to display the books for the logged in user.
So, I get the username from this line.
Then we fetch the details of borrowed books
with the condition username is equal to the logged-in user.
So, we get the list of books issued for the corresponding user.
Then, in successGreeting dot jsp we will display the list.
This is how your successGreeting dot jsp will look.
In this tutorial, we have learnt to:
Modify the login page to redirect to admin page
To fetch the book details
To fetch the borrowed book details and
To display the books borrowed by a logged in user.
To know more about the spoken tutorial project, watch the video available at the following link.
It summarizes the Spoken Tutorial project.
If you do not have good bandwidth, you can download and watch it.
The Spoken Tutorial Project team:
Conducts workshops using spoken tutorials.
Gives certificates to those who pass an online test.
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.
It is supported by the National Mission on Education through ICT, MHRD, Government of India.
More information on this mission is available at http://spoken-tutorial.org/NMEICT-Intro
The Library Management System has been contributed by a leading software MNC through their Corporate Social Responsibility Program.
They have also validated the content for this spoken tutorial.
This is Arya Ratish from IIT Bombay, signing off.
Thank you for joining.