HTTP Session Cart practical
REQUIREMENT
An online selling company needs a solution for their web application that they want to keep product details that are willing to purchase by users. The product list that the user is willing to purchase is called a cart. The cart must view each user with details and temporary. The cart will be clear when the user has closed the browser or automatic session timeout because this company does not want to keep details in the cart when the user left without purchasing at the moment.KNOWLEDGE NEED
HTTP Session.An HTTP session is a temporary object that provides by the server when a user is requesting something from a web application/ site.
If ten users (anywhere in the world) are requesting the same web application/ site, the server makes ten HTTP sessions for each user.
So HTTP session is a unique object for a user.
JSP is also known as the java server page.
JSP is a server-side programming technology that helps to create dynamic HTML content, methods. JSP mostly use to create HTML content with Java and JDBC.
Java Servlet.
Servlet is a component that can receive user requests access data, create responses and send responses to the target user. Can access the HTTP session, set and get parameters, set and get attributes from user request inside the servlet.
Basic HTML and CSS.

MAJOR STEPS
Create a new JSP and design a div for “add products” (to the database).Create a form to add products to the database.
Create a servlet and add products to the database.
Create your own database using java classes or use mysql or any as your need.
In the demo project, I have created a database using java classes to test my knowledge.
Create a new JSP (or use current JSP) and design a div for “view products”.
(what are the products in the database).
You can load data inside JSP because JSP has a feature that can access java with HTML.
Make sure the product view is visible to any user.
Add to cart button with each product view.
Create a servlet to add selected products to a list when the user clicks the add to cart button.
Access HTTP session (user unique) and create an attribute called cart.
Add selected product list to the cart attribute.
The list must update each time when user click add to cart button
Make sure this attribute is user unique.
Create a new JSP (or use current JSP) to design a div for “view cart”.
(what are the selected products that the user is willing to purchase).
You can load data inside JSP because JSP has a feature that can access java with HTML.
Make sure the product view is visible to the only user who added those products to the cart.
Make a remove button for each selected product.
If the user does not want to purchase a product, that can be removed from the cart.
Create a servlet to remove the selected product from the cart attribute.
EXTRA
You can use AJAX to load data without reloading the page.You can use Request Dispatcher instead of Redirect.
Add quantities for each product and make an input for entering a quantity before adding to the cart.
Add images to each product. Use Java file uploading to upload an image and keep the path with product details. View images.
Use pagination to view products.
That’s all !!!
Make your own project and practice. Memorize the main steps and keep thinking while developing.Follow the demo project given. The project is made using an IDE called Netbeans.
Find and copy JSPs, servlets/ java classes if you use another IDE.
The demo project is basic and clear. You can apply this to any of your projects.
Run the project and open “index.jsp” using two or more web browsers.
Add products to the database using one browser tab, reload all other browser tabs check what happens.
Add products to the cart. Reload all other browser tabs. Reload check what happens.
Try to understand the basics of the code.
Do not close any browser while testing. Because the demo database is created using java classes.
Try to use MYSQL or any other DBMS to save products and view.
Hope you enjoyed it, learned something new, and helped for better work.
Thank you for reading. See you with another practice.
Download demo project here
Comments
Post a Comment