Background

Writing Servlet + JSP again nowadays feels a bit retro.

The frontend world has long been full of React and Vue, and on the backend most projects start with Spring Boot. But I still think that writing an e-commerce demo by hand with Servlet and JSP is a great way to shore up Web fundamentals.

Because it doesn’t have so many frameworks hiding the details for you. How requests come in, how Session is stored, how pages navigate, how DAO queries the database—you have to write all of it yourself.

The project is here: yfgug/project

Features roughly look like this

This e-commerce platform isn’t a toy page; the basic shopping flow is complete:

  • User module: registration, login, logout, password change, shipping address modification.
  • Product module: category browsing, paginated queries, keyword search, product details.
  • Recommendation module: scrolling banners, popular recommendations, new product recommendations.
  • Shopping cart: Session-based cart storage, asynchronous product addition.
  • Order module: cart checkout, order generation, payment method selection.

Technically it uses traditional Java Web: Servlet, JSP, JSTL, Filter, DAO, Service. Database access uses Apache DBUtils; the connection pool configuration actually uses Druid, and the traditional dependency notes are also retained.

Session shopping cart

The shopping cart part really shows the flavor of a traditional Web project.

When the user clicks “Add to Cart”, the frontend requests goods_buy. The backend gets the Order object from Session; if there isn’t one, it creates a new one, then queries stock by product id, and if stock is sufficient, adds the product to the cart.

This logic isn’t complex, but it connects several fundamentals:

  • Session is not an abstract concept; it can really store the current user’s temporary state.
  • Servlet handles one request, but the shopping cart needs to persist across requests.
  • The backend cannot trust the frontend; stock still has to be checked before adding to the cart.

Previously I only knew Session as a session. After writing this, I understand more concretely that it is the key to maintaining state in many traditional Web applications.

The DAO layer also has pitfalls

When you don’t use an ORM, SQL stays very close to you.

DBUtils’ QueryRunner saves a lot of boilerplate code, and BeanHandler and MapListHandler make result set handling more comfortable. But you are still responsible for the SQL itself.

For example, with paginated queries, you can’t only think about how many rows the page displays; you also have to calculate:

  • Which page is current.
  • How many rows per page.
  • Total record count.
  • Total page count.
  • Where limit starts.

These things look trivial, but e-commerce list pages can’t do without them.

Why this kind of project still matters

After finishing this project, I understand better why Spring Boot is comfortable.

It’s not because Servlet/JSP can’t be used, but because in traditional Java Web too many things need to be managed by you personally:

  • Encoding filter.
  • Route mapping.
  • Session state.
  • JSP page navigation.
  • DAO hand-written SQL.
  • Dependency packages manually placed in WEB-INF/lib.

After writing it once, when you go back to Spring MVC and Spring Boot, you won’t feel that those auto-configurations are magic. They just package these old tasks well.

Final thoughts

This e-commerce platform isn’t modern, but it’s very suitable for practice.

It made me realize that a Web application is not just pages, and not just a database. A real project is a complete chain: the user clicks a button, the request enters the backend, the backend handles state and data, and then returns the result to the page.

Once this chain works end to end, learning whatever framework comes next is a little easier.