Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Building a Movie Ticket Booking System with Java Servlet Architecture

Tech May 12 3

System Roles and Permissions

The movie ticket reservasion platform supports two distinct user roles:

Administrator Functions:

  • User account management
  • Movie category administration
  • Film information management
  • Order processing and oversight
  • Message board administration

Customer Functions:

  • Account registration and authentication
  • Ticket purchasing operations
  • Personal order management
  • Information query capabilities

Technical Architecture

Backend Framework: Java Servlet Frontend Technologies: JSP, CSS, JavaScript, jQuery

MVC Pattern Implementation

The Model-View-Controller architectural pattern organizes the application into three interconnected components:

  • Model: Manages data operations including database interactions, business logic, and data validation
  • View: Handles user interface presentation and data visualization
  • Controller: Processes user requests, coordinates between model and view components

This separation enables independent development of presentation and business logic layers, improving maintainability and facilitating team collaboration.

Database Management

MySQL serves as the relational database management system, selected for its compact footprint, performance efficiency, and open-source availability. The system supports both MySQL 5.7 and 8.x versions.

Development Environment Requirements

  • Java Development Kit: JDK 1.8
  • IDE Compatibility: IntelliJ IDEA or Eclipse
  • Application Server: Apache Tomcat 7-10
  • Database: MySQL 5.7 or 8.x
  • Build Tool: Non-Maven project structure
  • Operating System: Windows

Core Implementation Examples

Database Configuration

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

    <bean id="dbConnection" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
        <property name="url" 
                  value="jdbc:mysql://localhost:3306/movie_booking?characterEncoding=utf8&amp;useSSL=false&amp;serverTimezone=UTC"/>
        <property name="username" value="root"/>
        <property name="password" value="root"/>
    </bean>

    <bean id="hibernateSession" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dbConnection"/>
        <property name="configLocation" value="classpath:hibernate.cfg.xml"/>
        <property name="mappingResources">
            <list>
                <value>com/entity/Admin.hbm.xml</value>
                <value>com/entity/Customer.hbm.xml</value>
                <value>com/entity/Message.hbm.xml</value>
                <value>com/entity/Genre.hbm.xml</value>
                <value>com/entity/Film.hbm.xml</value>
                <value>com/entity/OrderDetail.hbm.xml</value>
                <value>com/entity/Booking.hbm.xml</value>
            </list>
        </property>
    </bean>

    <bean id="customerDAO" class="com.repository.CustomerRepository">
        <property name="sessionFactory" ref="hibernateSession"/>
    </bean>

    <bean id="customerController" class="com.controller.CustomerController" scope="prototype">
        <property name="customerRepository" ref="customerDAO"/>
    </bean>
</beans>

Customer Management Implementation

package com.controller;

import java.util.List;
import java.util.Map;

import org.apache.struts2.ServletActionContext;
import com.repository.CustomerRepository;
import com.entity.Customer;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.util.ShoppingCart;

public class CustomerController extends ActionSupport {
    private Integer customerId;
    private String loginName;
    private String password;
    private String fullName;
    private String address;
    private String gender;
    private String phone;
    private String email;
    private String qqAccount;
    
    private CustomerRepository customerRepository;
    
    public String registerCustomer() {
        Customer newCustomer = new Customer();
        newCustomer.setLoginName(loginName);
        newCustomer.setPassword(password);
        newCustomer.setFullName(fullName);
        newCustomer.setAddress(address);
        newCustomer.setPhone(phone);
        newCustomer.setEmail(email);
        newCustomer.setGender(gender);
        newCustomer.setQqAccount(qqAccount);
        newCustomer.setActiveStatus("active");
        
        customerRepository.save(newCustomer);
        
        Map session = ServletActionContext.getContext().getSession();
        session.put("currentUser", newCustomer);
        return "registrationSuccess";
    }
    
    public String authenticateCustomer() {
        String query = "from Customer where loginName=? and password=?";
        Object[] parameters = {loginName, password};
        List<Customer> customers = customerRepository.getHibernateTemplate().find(query, parameters);
        
        if (customers.isEmpty()) {
            this.addActionError("Invalid credentials provided");
            return "authenticationFailed";
        } else {
            Map session = ServletActionContext.getContext().getSession();
            Customer authenticatedCustomer = customers.get(0);
            session.put("currentUser", authenticatedCustomer);
            
            ShoppingCart cart = new ShoppingCart();
            session.put("userCart", cart);
            
            return "authenticationSuccess";
        }
    }
    
    public String logoutCustomer() {
        Map session = ServletActionContext.getContext().getSession();
        session.remove("currentUser");
        return ActionSupport.SUCCESS;
    }
    
    // Getter and setter methods
    public void setCustomerRepository(CustomerRepository repository) {
        this.customerRepository = repository;
    }
    
    public CustomerRepository getCustomerRepository() {
        return customerRepository;
    }
}

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.