Skip to main content

Session Cart | Demo Project | Learn Java

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

Popular

Tkinter Login System | Demo Project | Learn Python

Python practical Requirement Simple user registration and login application. Three interfaces minimum Sign-in: This is the main interface. Enter email and password, then log in. And the option to create accounts for new users. Sign-up: This interface is used to register new users. All user details are saved in a text file. You can build your own structure to save data. Dashboard: This interface will pop up when the user sign-in is successful. This interface has a menu bar with submenu items and a simple text file. You can customize this as your own. All registered users are saved in a text file called “users”. Read the text file when the user is sign-in and write when the new user sign-up. Interfaces This is the main interface of the program also the sign-in interface. Enter email and password and press the sign-in button. The dashboard will be pop up if login is successful else show an error message. This is the interface when the user wants to create a new account. This inter...

How to get a proper Affidavit in Sri Lanka?

What is an Affidavit? An affidavit is a written statement by a person under an oath or affirmation. An affidavit is administered, signed, and sealed by a registered lawyer, the high court, and the ministry. An affidavit includes a related person's personal details, family details, document details, and a comparison of each document detail.  An affidavit includes an oath or affirmative statement to each document's comparison is true and it states about the same person even if there are some differences. An affidavit includes several signs and seals at the bottom of the statement. 1. Related person's signature. 2. The lawyer's name, signature, and seal. 3. The ministry's signature, and seal. The lawyer,  1. Should be registered in the high court. 2. Should have a valid seal. 3. Should able to issue high court receipts. The lawyer should meet all the requirements above to certify a valid affidavit What is the routine of collecting a proper affidavit in Sri Lanka? First...

How to keep your smartphone under control for secure privacy?

We people care too much about how people see themselves in the digital world. Your mobile device is the closest pathway to connect our physical world to the digital world. In the modern world, we work hard to maintain our physical world alongside our digital world through our mobile devices. As we know most companies provide amazing platforms and services free to keep ourselves attached to the digital world. In return, they use our data for advertising or marketing purposes and make profits. We spend hours daily on these platforms updating, maintaining ourselves and others. Many people earn money on these platforms some maintain a balanced schedule between the digital world and the physical world. These days we hear about users' privacy leaks, unnecessary usage of users' data, Sneaking up even if we don't use some free applications, services. However, we can't put a full stop to these because these large-scale companies need profits to keep themselves alive. They are cu...