How a-man24x7/train-booking-system works
1. Purpose and deployment
A server-rendered Java train-booking application for customers and administrators. It is deployed as a Maven WAR-style web application to Tomcat 9, with HTML pages under WebContent/ and servlet routing configured in WebContent/WEB-INF/web.xml. Browser entry is WebContent/index.html.
2. Request and presentation boundary
HTTP requests are handled by role- and use-case-specific Java servlets. Many *Fwd servlets appear to forward users to HTML views, while action servlets process form submissions and redirect/forward based on results.
• src/com/aman/servlets/UserLoginServlet.java
• src/com/aman/servlets/AdminLogin.java
• src/com/aman/servlets/ErrorHandlerServlet.java
Views are static HTML pages, including separate user/admin homes and booking/search/payment screens:
• WebContent/UserHome.html
• WebContent/AdminHome.html
• WebContent/BookTrains.html
3. Identity, roles, and session-oriented flows
Customer registration/login, profile updates, password changes, and logout are handled in the servlet layer and delegated to user services. Admin authentication and logout are separate flows. Role meaning is centralized as an enum, while user/admin entities are distinct beans.
• src/com/aman/service/UserService.java
• src/com/aman/servlets/UserRegServlet.java
• src/com/aman/constant/UserRole.java
4. Train catalog and admin management
The train subsystem owns listing, searching by route, fare/availability inquiries, and administrator CRUD-style schedule management. TrainService provides the business boundary; its implementation accesses persistence. Admin actions include add, update, cancel/delete, and view; user flows expose search and viewing.
• src/com/aman/service/TrainService.java
• src/com/aman/service/impl/TrainServiceImpl.java
• src/com/aman/beans/TrainBean.java
5. Booking lifecycle
Booking is a multi-step web flow: select a train, enter booking details, continue through payment handling, and persist a history record. Availability and cancellation are adjacent operations that must coordinate with train seat counts and booking history. The repository models booking/history separately from train data.
• src/com/aman/servlets/BookTrains.java
• src/com/aman/servlets/BookTrainPayment.java
• src/com/aman/service/impl/BookingServiceImpl.java
6. Persistence and data model
JDBC is the sole persistence integration. DBUtil reads connection configuration from src/application.properties and connects to the configured MySQL trainbook database. Core tables/entities are admin, customer, train, and history; booking identity/history uses transaction IDs.
• src/com/aman/utility/DBUtil.java
• src/com/aman/beans/BookingDetails.java
• src/com/aman/beans/HistoryBean.java
The web archive also contains WebContent/WEB-INF/lib/ojdbc8.jar, but the documented runtime database is MySQL; this driver is potentially legacy or unused.
7. Operational boundaries
The application depends on JDK 8, Apache Tomcat 9, Maven packaging, and a reachable MySQL instance. It has no REST/API tier or separate frontend runtime: browser HTML forms call servlet endpoints directly, servlets invoke services, services use JDBC, and outcomes return users to HTML pages or the error route.
• pom.xml
• WebContent/WEB-INF/web.xml
• src/com/aman/beans/TrainException.java
Components 16
Web application
Tomcat-hosted WAR request boundary.
- Browser · HTML forms invoke servlet endpoints directly.
- HTML views · User, admin, search, booking, and payment pages.
WebContent/index.html - Servlet routing · Maps servlet endpoints in the WAR.
WebContent/WEB-INF/web.xml - User servlets · Login, registration, profile, password, and logout flows.
src/com/aman/servlets/UserLoginServlet.java - Admin servlets · Separate administrator authentication and management flows.
src/com/aman/servlets/AdminLogin.java - Booking servlets · Coordinates train selection, details, and payment steps.
src/com/aman/servlets/BookTrains.java - Error handler · Receives failed-flow outcomes.
src/com/aman/servlets/ErrorHandlerServlet.java - Tomcat 9 WAR runtime · Hosts the Maven-packaged application.
pom.xml
Business services
- User service · Manages customer identity and account operations.
src/com/aman/service/UserService.java - User roles · Central role definition for user and admin flows.
src/com/aman/constant/UserRole.java - Train service · Searches trains and manages schedules, fares, and availability.
src/com/aman/service/TrainService.java - Train service implementation · JDBC-backed train catalog operations.
src/com/aman/service/impl/TrainServiceImpl.java - Booking service · Persists bookings/history and coordinates seats and cancellation.
src/com/aman/service/impl/BookingServiceImpl.java - Booking and train model · Train, booking, and history records carry lifecycle data.
src/com/aman/beans/BookingDetails.java
Persistence
- DB utility · Reads connection settings and opens database connections.
src/com/aman/utility/DBUtil.java - MySQL trainbook · Stores admin, customer, train, and history data.
Connections 25
- Browser → HTML views: loads pages
- Browser → Servlet routing: submits forms
- Tomcat 9 WAR runtime → Servlet routing: deploys
- Servlet routing → User servlets: maps user endpoints
- Servlet routing → Admin servlets: maps admin endpoints
- Servlet routing → Booking servlets: maps booking endpoints
- User servlets → User service: account operations
- User servlets → User roles: applies roles
- Admin servlets → User service: authenticates admin
- Admin servlets → Train service: manages schedules
- Booking servlets → Train service: checks route and seats
- Booking servlets → Booking service: creates and pays booking
- User servlets → HTML views: forwards or redirects
- Admin servlets → HTML views: forwards or redirects
- Booking servlets → HTML views: returns flow outcome
- User servlets → Error handler: failure route
- Booking servlets → Error handler: failure route
- Train service → Train service implementation: implemented by
- Train service implementation → DB utility: uses JDBC
- Booking service → DB utility: uses JDBC
- User service → DB utility: uses JDBC
- DB utility → MySQL trainbook: connects to
- Train service → Booking and train model: uses train records
- Booking service → Booking and train model: persists booking history
- Booking service → Train service: coordinates seat counts