User Registration in Spring Boot, Hibernate, JPA, JSP and MYSQL

User registration is a fundamental aspect of many web applications. In this tutorial, we will walk you through the process of creating a user registration system using Spring Boot, Hibernate, JPA (Java Persistence API), JSP (JavaServer Pages), and MySQL. These technologies are widely used in building robust and scalable web applications.

Prerequisites

Before we begin, ensure you have the following tools and technologies installed:

Java Development Kit (JDK): You’ll need Java to run the Spring Boot application. You can download the latest JDK from the official Oracle website.

Spring Boot: You can create a Spring Boot project using Spring Initializr or your preferred IDE (Integrated Development Environment).

MySQL Database: You should have MySQL installed and configured on your machine. If you don’t have MySQL, you can download it from the official website.

Integrated Development Environment (IDE): Use an IDE like IntelliJ IDEA or Eclipse for ease of development. These IDEs offer built-in support for Spring Boot.

Setting Up the Project

Let’s start by setting up a Spring Boot project with the necessary dependencies.

  • Create a new Spring Boot project using Spring Initializr or your IDE.
  • Add the following dependencies to your pom.xml file:

While you working with web applications in Java and Spring Boot, you must have libraries or dependencies, Get all the important and required dependencies from pom.xml in Spring Boot.

  • Configure your database connection in the application.properties file:

application.properties

#prefix and suffix configration


#Database Configrations
spring.datasource.url=jdbc:mysql://localhost:3306/bugtrackingyt?createDatabaseIfNotExist=true
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.database-platform = org.hibernate.dialect.MySQL8Dialect
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto = update
server.port = 8080
#context Path 

server.servlet.context-path=/BugTrackingYT


#URL: http://localhost:8080/BugTrackingYT/

Replace your_database_name, your_username, and your_password with your MySQL database details.

Creating the User Entity

Next, let’s create a User entity class that represents a user in our application. This entity will be mapped to a database table using JPA.

UserDTO.java

package com.bugtackingyt.dto;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

import lombok.Getter;
import lombok.Setter;

@Entity
@Getter
@Setter
@Table(name = "user")
public class UserDTO extends BaseDTO {

 @Column(name = "firstName", length = 755)
 private String firstName;
 
 @Column(name = "lastName", length = 755)
 private String lastName;
 
 @Column(name = "dob", length = 755)
 private Date dob;
 
 @Column(name = "gender", length = 755)
 private String gender;
 
 @Column(name = "email", length = 755)
 private String email;
 
 @Column(name = "password", length = 755)
 private String password;
 
 @Column(name = "phoneNumber", length = 755)
 private String phoneNumber;
 
 @Column(name = "userRole", length = 755)
 private String userRole;
 

 
}

BugtackingytApplication.java

package com.bugtackingyt;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class BugtackingytApplication {

 public static void main(String[] args) {
  SpringApplication.run(BugtackingytApplication.class, args);
 }

}

BugtackingytConfiguration.java

package com.bugtackingyt.config;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.UrlBasedViewResolver;
import org.springframework.web.servlet.view.tiles3.TilesConfigurer;
import org.springframework.web.servlet.view.tiles3.TilesView;


@Configuration
@EnableWebMvc
@EnableAutoConfiguration
public class BugtackingytConfiguration implements WebMvcConfigurer {

 @Bean(name = "viewResolver")
 public ViewResolver getViewResolver() {
  UrlBasedViewResolver viewResolver = new UrlBasedViewResolver();
  viewResolver.setViewClass(TilesView.class);
  return viewResolver;
 }

 @Bean(name = "tilesConfigure")
 public TilesConfigurer getTilesConfigure() {
  TilesConfigurer tilesConfigure = new TilesConfigurer();
  tilesConfigure.setDefinitions("/WEB-INF/tiles.xml");
  return tilesConfigure;
 }

 public void addResourceHandlers(ResourceHandlerRegistry registry) {
  registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
 }
}

HomeCtl.java

package com.bugtackingyt.ctl;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class HomeCtl {

 @GetMapping("/")
 public String homePage() {
  return "home";
 }
 
}

UserCtl.java

package com.bugtackingyt.ctl;

import javax.naming.Binding;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;

import com.bugtackingyt.dto.UserDTO;
import com.bugtackingyt.exeception.RecordNotFoundException;
import com.bugtackingyt.form.UserForm;
import com.bugtackingyt.service.UserService;

@Controller
public class UserCtl {

 @Autowired
 public UserService userService;
 
 @GetMapping("/registration")
 public String registrationPage(@ModelAttribute("form")UserForm form) {
  
  return "registration";
 }
 
 @GetMapping("/login")
 public String loginPage(@ModelAttribute("form")UserForm form) {
  
  return "login";
 }
 
 @PostMapping("/AddUser")
 public String save(@Valid @ModelAttribute("form")UserForm form, BindingResult bindingResult, Model model ) {

  try {
   
   if(bindingResult.hasErrors()) {
    System.out.println("bindingResult: "+bindingResult);
    return "registration";
   }else {
    UserDTO user = (UserDTO)form.getDTO();
    user.setUserRole("User");
    userService.AddUser(user);
    model.addAttribute("success", "User is registed Successfully.......");

    
   }
   return "registration";
  }catch (RecordNotFoundException e) {
   // TODO: handle exception
   model.addAttribute("error", e.getMessage());
   e.printStackTrace();
  

   return "registration";
  }
  
   
  
 }
 

 
 }

UserDAO.java

package com.bugtackingyt.dao;

import org.springframework.data.jpa.repository.JpaRepository;

import com.bugtackingyt.dto.UserDTO;

public interface UserDAO extends JpaRepository<UserDTO, Long> {
 
 public UserDTO findByEmailAndPassword(String email, String password);
 public UserDTO findByEmail(String email);
 public UserDTO findById(long id);

}

BaseDTO.java

package com.bugtackingyt.dto;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

import lombok.Getter;
import lombok.Setter;

@MappedSuperclass
@Getter
@Setter
public class BaseDTO {
 
 @Id
 @GeneratedValue(strategy = GenerationType.IDENTITY)
 @Column(name = "Id")
 protected long id;

}

RecordNotFoundException.java

package com.bugtackingyt.exeception;


import java.util.Date;

public class ExceptionResponse {
 
 private Date timestamp;
 private String message;
 private String details;
 
 
 public ExceptionResponse(Date timestamp, String message, String details) {
  super();
  this.timestamp = timestamp;
  this.message = message;
  this.details = details;
 }

 

 public Date getTimestamp() {
  return timestamp;
 }


 public void setTimestamp(Date timestamp) {
  this.timestamp = timestamp;
 }


 public String getMessage() {
  return message;
 }


 public void setMessage(String message) {
  this.message = message;
 }


 public String getDetails() {
  return details;
 }


 public void setDetails(String details) {
  this.details = details;
 }
 
 
 
 

}

UserForm.java

package com.bugtackingyt.form;


import javax.validation.constraints.NotEmpty;

import com.bugtackingyt.dto.BaseDTO;
import com.bugtackingyt.dto.UserDTO;
import com.bugtackingyt.utlity.DataUtility;

import lombok.Getter;
import lombok.Setter;


@Getter
@Setter
public class UserForm extends BaseDTO {


 @NotEmpty(message = "First Name is required")
 private String firstName;
 
 @NotEmpty(message = "Last Name is required")
    private String lastName;

 private String dob;
 private String gender;
 
 @NotEmpty(message = "Email is required")
 private String email;

 @NotEmpty(message = "Password is required")
    private String password;
 
 @NotEmpty(message = "Phone Number is required")
 private String phoneNumber;
 
 

 public UserDTO getDTO() {
  // TODO Auto-generated method stub
 UserDTO dto = new UserDTO();
 dto.setFirstName(firstName);
 dto.setLastName(lastName);
 dto.setDob(DataUtility.getDate1(dob));
 dto.setGender(gender);
 dto.setEmail(email);
 dto.setPassword(password);
 dto.setPhoneNumber(phoneNumber);
  
  return dto;
 }
 

 public void populate(UserDTO dto) {
  
  firstName = dto.getFirstName();
  lastName = dto.getLastName();
  dob = DataUtility.getDateString1(dto.getDob());
  gender = dto.getGender();
  email = dto.getEmail();
  password = dto.getPassword();
  phoneNumber = dto.getPhoneNumber();
  
 }
 
}

UserService.java

package com.bugtackingyt.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bugtackingyt.dao.UserDAO;
import com.bugtackingyt.dto.UserDTO;
import com.bugtackingyt.exeception.RecordNotFoundException;

@Service
public class UserService {

 @Autowired
 public UserDAO userDao;
 
 public UserDTO AddUser(UserDTO user) {
  UserDTO userDto = null;
  UserDTO udto = userDao.findByEmail(user.getEmail());
  
  if(udto == null) {
   userDto = 	userDao.save(user);
  }else {
   throw new RecordNotFoundException("Email is alredy Registered..");
  }
  
  return userDto;

 }
 
}

DataUtility.java 

DataUtility

DataValidator.java 

DataValidator

footer.jsp

<!-- Footer -->
<%@page import="java.util.Date"%>
<div style="margin-top: 50px;">
<footer class="page-footer font-small blue">

  <!-- Copyright -->
     <div class="footer-copyright text-center py-3">© <%=new Date().getYear()+1900 %> Copyright:
    <a href="${pageContext.request.contextPath}/home"> <span class="text-center">Bug Tracking Management</span></a>
  </div> 
  <!-- Copyright -->

</footer>
</div>
<!-- Footer --></html>

header.jsp

<%@taglib uri="http://www.springframework.org/tags/form" prefix="sf"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="crt"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="s"%>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style><%@include file="/WEB-INF/css/header.css"%></style>
<link rel="stylesheet"
 href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css"
 integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
 crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
 integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
 crossorigin="anonymous"></script>
<script
 src="https://cdn.jsdelivr.net/npm/popper.js@1.12.9/dist/umd/popper.min.js"
 integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
 crossorigin="anonymous"></script>
<script
 src="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/js/bootstrap.min.js"
 integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
 crossorigin="anonymous"></script>

<nav class="navbar navbar-expand-lg navbar-light bg-light" style="background: black !important;">
 <div class="container-fluid">
  <a class="navbar-brand" href="${pageContext.request.contextPath}/home" style="color: white;">Bug Tracking</a>
  <button class="navbar-toggler" type="button" data-bs-toggle="collapse"
   data-bs-target="#navbarNav" aria-controls="navbarNav"
   aria-expanded="false" aria-label="Toggle navigation">
   <span class="navbar-toggler-icon"></span>
  </button>
  <div class="collapse navbar-collapse" id="navbarNav" style="justify-content: space-between;">
   <div class="float-left">
    <ul class="navbar-nav">
     <li class="nav-item"><a class="nav-link active"
      aria-current="page" href="${pageContext.request.contextPath}/" style="color: white;">Home</a>
     </li>

     <c:if test="${sessionScope.user == null}">
      <li class="nav-item"><a class="nav-link"
       href="${pageContext.request.contextPath}/registration" style="color: white;">SignUp</a>
      </li>
      <li class="nav-item"><a class="nav-link"
       href="${pageContext.request.contextPath}/login" style="color: white;">Login</a></li>
     </c:if>

     <c:if test="${sessionScope.user.userRole == 'Admin'}">
      <li class="nav-item dropdown"><a
       class="nav-link dropdown-toggle" href="#" id="navbarDropdown"
       role="button" data-toggle="dropdown" aria-haspopup="true"
       aria-expanded="false" style="color: white;"> Users </a>
       <div class="dropdown-menu" aria-labelledby="navbarDropdown">
        <a class="dropdown-item"
         href="${pageContext.request.contextPath}/registration">Add
         User</a> <a class="dropdown-item"
         href="${pageContext.request.contextPath}/userList">User
         List</a>
       </div></li>


      <li class="nav-item dropdown"><a
       class="nav-link dropdown-toggle" href="#" id="navbarDropdown"
       role="button" data-toggle="dropdown" aria-haspopup="true"
       aria-expanded="false" style="color: white;"> Movies </a>
       <div class="dropdown-menu" aria-labelledby="navbarDropdown">
        <a class="dropdown-item"
         href="${pageContext.request.contextPath}/movie">Add Movie</a> <a
         class="dropdown-item"
         href="${pageContext.request.contextPath}/movieList">Movies
         List</a> <a class="dropdown-item"
         href="${pageContext.request.contextPath}/movieGrid">Movies
         Booking View</a>

       </div></li>

      <li class="nav-item dropdown"><a
       class="nav-link dropdown-toggle" href="#" id="navbarDropdown"
       role="button" data-toggle="dropdown" aria-haspopup="true"
       aria-expanded="false" style="color: white;"> Parking </a>
       <div class="dropdown-menu" aria-labelledby="navbarDropdown">
        <a class="dropdown-item"
         href="${pageContext.request.contextPath}/parking">Add
         Parking</a> <a class="dropdown-item"
         href="${pageContext.request.contextPath}/parkinglist">View
         List</a>
       </div></li>
     
      <li class="nav-item dropdown"><a
       class="nav-link dropdown-toggle" href="#" id="navbarDropdown"
       role="button" data-toggle="dropdown" aria-haspopup="true"
       aria-expanded="false" style="color: white;"> Food </a>
       <div class="dropdown-menu" aria-labelledby="navbarDropdown">
        <a class="dropdown-item"
         href="${pageContext.request.contextPath}/foodStall">Add
         Stall</a> <a class="dropdown-item"
         href="${pageContext.request.contextPath}/foodStallList">Stall
         List</a>
        <!-- 	<a class="dropdown-item"
         href="${pageContext.request.contextPath}/viewFoodMenu">Add Food Menu</a>
         
         <a class="dropdown-item"
         href="${pageContext.request.contextPath}/foodMenu">View Food Menu</a>  -->
         
         <a class="dropdown-item"
         href="${pageContext.request.contextPath}/viewCart">Food Cart</a>	
       </div></li>
       
     <li class="nav-item dropdown"><a
       class="nav-link dropdown-toggle" href="#" id="navbarDropdown"
       role="button" data-toggle="dropdown" aria-haspopup="true"
       aria-expanded="false" style="color: white;"> Game </a>
       <div class="dropdown-menu" aria-labelledby="navbarDropdown">
        <a class="dropdown-item"
         href="${pageContext.request.contextPath}/game">Add
         Game</a> <a class="dropdown-item"
         href="${pageContext.request.contextPath}/gameList">Game
         List</a>
         
         <a class="dropdown-item"
         href="${pageContext.request.contextPath}/gameRecharge">Recharge</a>
         
       </div></li>
       


      <li class="nav-item dropdown"><a
       class="nav-link dropdown-toggle" href="#" id="navbarDropdown"
       role="button" data-toggle="dropdown" aria-haspopup="true"
       aria-expanded="false" style="color: white;"> Shop </a>
       <div class="dropdown-menu" aria-labelledby="navbarDropdown">
        <a class="dropdown-item"
         href="${pageContext.request.contextPath}/shop">Add
         Shop</a> <a class="dropdown-item"
         href="${pageContext.request.contextPath}/shopList">Shop
         List</a>
       </div></li>
       
       
        <li class="nav-item dropdown"><a
       class="nav-link dropdown-toggle" href="#" id="navbarDropdown"
       role="button" data-toggle="dropdown" aria-haspopup="true"
       aria-expanded="false" style="color: white;"> Event </a>
       <div class="dropdown-menu" aria-labelledby="navbarDropdown">
        <a class="dropdown-item"
         href="${pageContext.request.contextPath}/event">Add
         Event</a> <a class="dropdown-item"
         href="${pageContext.request.contextPath}/eventList">Event
         List</a>
       </div></li>
       
       
      <li class="nav-item dropdown"><a
       class="nav-link dropdown-toggle" href="#" id="navbarDropdown"
       role="button" data-toggle="dropdown" aria-haspopup="true"
       aria-expanded="false" style="color: white;"> Job </a>
       <div class="dropdown-menu" aria-labelledby="navbarDropdown">
        <a class="dropdown-item"
         href="${pageContext.request.contextPath}/job">Add
         Job</a> <a class="dropdown-item"
         href="${pageContext.request.contextPath}/jobList">Job
         List</a>
         
         <a class="dropdown-item"
         href="${pageContext.request.contextPath}/applyjobList">Job
         Application</a>
         
       </div></li>							
         <li class="nav-item dropdown"><a
       class="nav-link dropdown-toggle" href="#" id="navbarDropdown"
       role="button" data-toggle="dropdown" aria-haspopup="true"
       aria-expanded="false" style="color: white;"> Deal </a>
       <div class="dropdown-menu" aria-labelledby="navbarDropdown">
        <a class="dropdown-item"
         href="${pageContext.request.contextPath}/deal">Add
         Deal</a> <a class="dropdown-item"
         href="${pageContext.request.contextPath}/dealList">Deal
         List</a>									
       </div></li>



      <li class="nav-item dropdown"><a
       class="nav-link dropdown-toggle" href="#" id="navbarDropdown"
       role="button" data-toggle="dropdown" aria-haspopup="true"
       aria-expanded="false" style="color: white;"> Bookings History </a>
       <div class="dropdown-menu" aria-labelledby="navbarDropdown">
        <a class="dropdown-item"
         href="${pageContext.request.contextPath}/movieBookingList">Movie
         Booking</a> <a class="dropdown-item"
         href="${pageContext.request.contextPath}/bookinglist">Parking
         Booking</a>
         
        <a class="dropdown-item"
         href="${pageContext.request.contextPath}/foodBookingHistory">Food Booking</a>
       </div></li>

      <li class="nav-item dropdown"><a
       class="nav-link dropdown-toggle" href="#" id="navbarDropdown"
       role="button" data-toggle="dropdown" aria-haspopup="true"
       aria-expanded="false" style="color: white;"> Payment History </a>
       <div class="dropdown-menu" aria-labelledby="navbarDropdown">
        <a class="dropdown-item"
         href="${pageContext.request.contextPath}/paymentlist">
         Payment History</a>
        <a class="dropdown-item"
         href="${pageContext.request.contextPath}/foodPaymentList">
         Food Payment History</a>	
         
       </div></li>

     </c:if>

     <c:if test="${sessionScope.user.userRole == 'User'}">
      <li class="nav-item dropdown"><a
       class="nav-link dropdown-toggle" href="#" id="navbarDropdown"
       role="button" data-toggle="dropdown" aria-haspopup="true"
       aria-expanded="false" style="color: white;"> Movies </a>
       <div class="dropdown-menu" aria-labelledby="navbarDropdown">
        <a class="dropdown-item"
         href="${pageContext.request.contextPath}/movieList">Movies
         List</a> <a class="dropdown-item"
         href="${pageContext.request.contextPath}/movieGrid">Book
         Movie Ticket</a>

       </div></li>


      <li class="nav-item dropdown"><a
       class="nav-link dropdown-toggle" href="#" id="navbarDropdown"
       role="button" data-toggle="dropdown" aria-haspopup="true"
       aria-expanded="false" style="color: white;"> Parking </a>
       <div class="dropdown-menu" aria-labelledby="navbarDropdown">
        <a class="dropdown-item"
         href="${pageContext.request.contextPath}/parkinglist">Book
         Parking Slot</a>
       </div></li>
       
       
        <li class="nav-item dropdown"><a
       class="nav-link dropdown-toggle" href="#" id="navbarDropdown"
       role="button" data-toggle="dropdown" aria-haspopup="true"
       aria-expanded="false" style="color: white;"> Food </a>
       <div class="dropdown-menu" aria-labelledby="navbarDropdown">
       

         <a class="dropdown-item"
         href="${pageContext.request.contextPath}/foodStallList">View Food</a>
         
         <a class="dropdown-item"
         href="${pageContext.request.contextPath}/viewCart">Food Cart</a>
        
         
       </div></li>
       
       
         <li class="nav-item dropdown"><a
       class="nav-link dropdown-toggle" href="#" id="navbarDropdown"
       role="button" data-toggle="dropdown" aria-haspopup="true"
       aria-expanded="false" style="color: white;"> Game </a>
       <div class="dropdown-menu" aria-labelledby="navbarDropdown">
         <a class="dropdown-item"
         href="${pageContext.request.contextPath}/gameList">Game
         List</a>
         
         <a class="dropdown-item"
         href="${pageContext.request.contextPath}/gameRecharge">Recharge</a>
         
       </div></li>
       
        <li class="nav-item dropdown"><a
       class="nav-link dropdown-toggle" href="#" id="navbarDropdown"
       role="button" data-toggle="dropdown" aria-haspopup="true"
       aria-expanded="false" style="color: white;"> Shop </a>
       <div class="dropdown-menu" aria-labelledby="navbarDropdown">
         <a class="dropdown-item"
         href="${pageContext.request.contextPath}/shopList">Shop
         List</a>
       </div></li>
       
       
        <li class="nav-item dropdown"><a
       class="nav-link dropdown-toggle" href="#" id="navbarDropdown"
       role="button" data-toggle="dropdown" aria-haspopup="true"
       aria-expanded="false" style="color: white;"> Event </a>
       <div class="dropdown-menu" aria-labelledby="navbarDropdown">
         <a class="dropdown-item"
         href="${pageContext.request.contextPath}/eventList">Event
         List</a>
       </div></li>
       
       
         <li class="nav-item dropdown"><a
       class="nav-link dropdown-toggle" href="#" id="navbarDropdown"
       role="button" data-toggle="dropdown" aria-haspopup="true"
       aria-expanded="false" style="color: white;"> Job </a>
       <div class="dropdown-menu" aria-labelledby="navbarDropdown">
         <a class="dropdown-item"
         href="${pageContext.request.contextPath}/jobList">Job
         List</a>
         
         <a class="dropdown-item"
         href="${pageContext.request.contextPath}/applyjobList">Job
         Application</a>
         
       </div></li>
       
        <li class="nav-item dropdown"><a
       class="nav-link dropdown-toggle" href="#" id="navbarDropdown"
       role="button" data-toggle="dropdown" aria-haspopup="true"
       aria-expanded="false" style="color: white;"> Deal </a>
       <div class="dropdown-menu" aria-labelledby="navbarDropdown">
         <a class="dropdown-item"
         href="${pageContext.request.contextPath}/dealList">Deal
         List</a>									
       </div></li>
       

      <li class="nav-item dropdown"><a
       class="nav-link dropdown-toggle" href="#" id="navbarDropdown"
       role="button" data-toggle="dropdown" aria-haspopup="true"
       aria-expanded="false" style="color: white;"> Bookings History </a>
       <div class="dropdown-menu" aria-labelledby="navbarDropdown">
        <a class="dropdown-item"
         href="${pageContext.request.contextPath}/movieBookingList">Movie
         Booking</a> <a class="dropdown-item"
         href="${pageContext.request.contextPath}/bookinglist">Parking
         Booking</a>
         
         <a class="dropdown-item"
         href="${pageContext.request.contextPath}/foodBookingHistory">Food Booking</a>
         
       </div></li>

      <li class="nav-item dropdown"><a
       class="nav-link dropdown-toggle" href="#" id="navbarDropdown"
       role="button" data-toggle="dropdown" aria-haspopup="true"
       aria-expanded="false" style="color: white;"> Payment History </a>
       <div class="dropdown-menu" aria-labelledby="navbarDropdown">
        <a class="dropdown-item"
         href="${pageContext.request.contextPath}/paymentlist">
         Payment History</a>
       </div></li>

     </c:if>



    </ul>
   </div>
   <div class="float-right" style="margin-left: 100px">
    <ul class="navbar-nav">
     <c:if test="${sessionScope.user != null}">
      	 <!--  <li class="nav-item"><a class="nav-link"
       href="${pageContext.request.contextPath}/logout" style="color: white;">Logout</a></li>
      <li class="nav-item"><a class="nav-link"
       href="${pageContext.request.contextPath}/userEdit?id=${sessionScope.user.id}" style="color: white;">My
        Profile</a></li>  -->
          <li class="nav-item dropdown"><a
       class="nav-link dropdown-toggle" href="#" id="navbarDropdown"
       role="button" data-toggle="dropdown" aria-haspopup="true"
       aria-expanded="false" style="color: white;"> <i class="fa fa-user" style="color:white; font-size: 20px;"></i> </a>
       
       <div class="dropdown-menu profile-dropdown" aria-labelledby="navbarDropdown">
        <a class="dropdown-item"
         href="${pageContext.request.contextPath}/userEdit?id=${sessionScope.user.id}">
         View Profile</a> <a class="dropdown-item"
         href="${pageContext.request.contextPath}/logout">Logout</a>

       </div></li>	
     </c:if>
    </ul>
   </div>
  </div>
 </div>
</nav>

businessMessage.jsp

<%@taglib uri="http://www.springframework.org/tags" prefix="s"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@page isELIgnored="false"%>

<c:if test="${success != null}">
 <div  class="alert alert-success" role="alert">${success}</div>
</c:if>
<c:if test="${error != null}">
 <div class="alert alert-danger" role="alert">${error}</div>
</c:if>

home.jsp

<div class="jumbotron text-center" style="position: relative; min-height: 10vh">
 <h1>Bug Tracking Management For YT tutorial</h1>
</div>

registration.jsp

<%@page import="java.text.DateFormat"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="sf"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="crt"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="s"%>
<%@page import="java.util.Date"%>

<%
DateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd");
%>

<body>
 <section class="vh-100 gradient-custom ">
  <div class="container py-5 h-100">
   <div
    class="row d-flex justify-content-center align-items-center h-100">
    <div class="col-md-5 col-lg-5 col-xl-4 image-class">
     <img
      src="https://i.pinimg.com/736x/4b/39/a9/4b39a94252cddcc7d20326c140278c4e.jpg"
      class="img-fluid" alt="Phone image">
    </div>
    <div class="col-md-9 col-lg-7 col-xl-7 offset-xl-1">
     <div class="card shadow-2-strong card-registration">
      <div class="card-body p-4 p-md-5">
       <%@include file="businessMessage.jsp"%>
       <c:choose>
        <c:when test="${form.id>0}">
         <h3 class="mb-4 pb-2 pb-md-0 mb-md-5">Profile</h3>
        </c:when>

        <c:otherwise>
         <h3 class="mb-4 pb-2 pb-md-0 mb-md-5">Registration Form</h3>
        </c:otherwise>
       </c:choose>

       <sf:form method="post"
        action="${pageContext.request.contextPath}/AddUser"
        modelAttribute="form">
        <sf:input type="hidden" id="id"
         class="form-control form-control-lg" path="id" name="id"
         value="${form.id}" />
        <div class="row">
         <div class="col-md-6 mb-4">
          <div class="form-outline">
           <s:bind path="firstName">
            <label class="form-label" for="firstName">First Name</label>
            <sf:input type="text" id="firstName"
             class="form-control form-control-lg" path="firstName"
             name="firstName" />
            <font color="red" style="font-size: 15px"><sf:errors
              path="${status.expression}" /></font>
           </s:bind>

          </div>

         </div>
         <div class="col-md-6 mb-4">

          <div class="form-outline">
           <s:bind path="lastName">
            <label class="form-label" for="lastName">Last Name</label>
            <sf:input type="text" id="lastName"
             class="form-control form-control-lg" path="lastName" />
            <font color="red" style="font-size: 15px"><sf:errors
              path="${status.expression}" /></font>
           </s:bind>
          </div>

         </div>

        </div>

        <div class="row">
         <div class="col-md-6 mb-4 d-flex align-items-center">
          <s:bind path="dob">
           <div class="form-outline datepicker w-100">
            <label for="birthdayDate" class="form-label">Date of
             birth</label>
            <sf:input type="date" class="form-control form-control-lg"
             id="dob" path="dob" placeholder="dd/MM/yyyy" />
            <font color="red" style="font-size: 15px"><sf:errors
              path="${status.expression}" /></font>
           </div>
          </s:bind>

         </div>
         <div class="col-md-6 mb-4">

          <label for="gender" class="form-label">Gender </label><br />
          <s:bind path="gender">
           <div class="form-check form-check-inline">
            <input class="form-check-input" type="radio" id="gender"
             value="Female" checked name="gender" /> <label
             class="form-check-label" for="femaleGender">Female</label>
           </div>

           <div class="form-check form-check-inline">
            <input class="form-check-input" type="radio" id="gender"
             value="Male" name="gender" /> <label
             class="form-check-label" for="maleGender">Male</label>
           </div>

           <div class="form-check form-check-inline">
            <input class="form-check-input" type="radio" id="gender"
             value="Other" name="gender" /> <label
             class="form-check-label" for="otherGender">Other</label>
           </div>
          </s:bind>
         </div>
        </div>


        <div class="row">

         <c:choose>

          <c:when test="${form.id>0}">
           <div class="col-md-6 mb-4 pb-2">
            <s:bind path="email">
             <div class="form-outline">
              <label class="form-label" for="emailAddress">Email</label>
              <sf:input type="email" id="emailAddress"
               class="form-control form-control-lg" path="email"
               readonly="true" />
              <font color="red" style="font-size: 15px"><sf:errors
                path="${status.expression}" /></font>
             </div>
            </s:bind>

           </div>
          </c:when>
          <c:otherwise>
           <div class="col-md-6 mb-4 pb-2">
            <s:bind path="email">
             <div class="form-outline">
              <label class="form-label" for="emailAddress">Email</label>
              <sf:input type="email" id="emailAddress"
               class="form-control form-control-lg" path="email" />
              <font color="red" style="font-size: 15px"><sf:errors
                path="${status.expression}" /></font>
             </div>
            </s:bind>

           </div>

          </c:otherwise>
         </c:choose>


         <div class="col-md-6 mb-4 pb-2">
          <s:bind path="password">
           <div class="form-outline">
            <label class="form-label" for="emailAddress">Password</label>
            <sf:input type="password" id="emailAddress"
             class="form-control form-control-lg" path="password" />
            <font color="red" style="font-size: 15px"><sf:errors
              path="${status.expression}" /></font>
           </div>
          </s:bind>
         </div>
         <div class="col-md-6 mb-4 pb-2">
          <s:bind path="phoneNumber">
           <div class="form-outline">
            <label class="form-label" for="phoneNumber">Phone
             Number</label>
            <sf:input type="tel" id="phoneNumber"
             class="form-control form-control-lg" path="phoneNumber" />
            <font color="red" style="font-size: 15px"><sf:errors
              path="${status.expression}" /></font>
           </div>
          </s:bind>
         </div>
        </div>


        <c:choose>
         <c:when test="${form.id>0}">
          <div>
           <input class="btn btn-primary btn-lg" type="submit"
            value="Update" />
          </div>
         </c:when>

         <c:otherwise>
          <div>
           <input class="btn btn-primary btn-lg" type="submit"
            value="Submit" />
          </div>
         </c:otherwise>
        </c:choose>

       </sf:form>

      </div>
     </div>
    </div>
   </div>
  </div>
 </section>
</body>

layout.jsp

<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<html>
<head>
<title><tiles:getAsString name="title" /></title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link
 href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css"
 rel="stylesheet"
 integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x"
 crossorigin="anonymous">
 <link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous"/>
<script
 src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js"
 integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4"
 crossorigin="anonymous"></script>
<script
 src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js"
 integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p"
 crossorigin="anonymous"></script>
<script
 src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.min.js"
 integrity="sha384-Atwg2Pkwv9vp0ygtn1JAojH0nYbwNJLPhwyoVbhoPwBhjQPR5VtM2+xf0Uwh9KtT"
 crossorigin="anonymous"></script>
<link rel="stylesheet"
 href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<link rel="stylesheet" href="resources/css/style.css">

<script type="text/javascript">
 $(function() {
  $("#datepicker").datepicker({
   changeMonth : true,
   changeYear : true,
   defaultDate : '01/01/1995'
  });
 });

 $(function() {
  $("#datepicker1").datepicker({
   changeMonth : true,
   changeYear : true
  });
 });
</script>
<script language="javascript">
 $(function() {
  $("#selectall").click(function() {
   $('.case').attr('checked', this.checked);
  });
  $(".case").click(function() {

   if ($(".case").length == $(".case:checked").length) {
    $("#selectall").attr("checked", "checked");
   } else {
    $("#selectall").removeAttr("checked");
   }

  });
 });
</script>
<style type="text/css">
.blockquote {
  padding: 20px;
  box-shadow:
       inset 0 -3em 3em rgba(0,0,0,0.1),
             0 0  0 2px rgb(255,255,255),
             0.3em 0.3em 1em rgba(0,0,0,0.3);
}
.imageHeight{
 height: 320px;
}
.linkSize{
 font-size: 14px;
}
</style>
</head>
<body >
 <div>
  <tiles:insertAttribute name="header" />
  <tiles:insertAttribute name="body" />
  <tiles:insertAttribute name="footer" />
 </div>
</body>
</html>

tiles.xml

<?xml version="1.0" encoding="UTF-8" ?>  
<!DOCTYPE tiles-definitions PUBLIC  
       "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"  
       "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">          
<tiles-definitions>  
 
    <!-- Base Define -->
    <definition name="base.definition" template="/WEB-INF/layouts/layout.jsp">  
        <put-attribute name="title" value="" />  
        <put-attribute name="header" value="/WEB-INF/basefragments/header.jsp" />  
        <put-attribute name="body" value="" />  
        <put-attribute name="footer" value="/WEB-INF/basefragments/footer.jsp" />  
    </definition>  
 
 	<!-- Home Page  -->
    <definition name="home" extends="base.definition">  
        <put-attribute name="title" value="Home" />  
        <put-attribute name="body" value="/WEB-INF/bodyfragments/home.jsp" />  
    </definition>   
    
     	<!-- Registration Page  -->
    <definition name="registration" extends="base.definition">  
        <put-attribute name="title" value="Home" />  
        <put-attribute name="body" value="/WEB-INF/bodyfragments/registration.jsp" />  
    </definition>  
    
     	<!-- Login Page  -->
    <definition name="login" extends="base.definition">  
        <put-attribute name="title" value="Home" />  
        <put-attribute name="body" value="/WEB-INF/bodyfragments/login.jsp" />  
    </definition>  
     	
    
   
</tiles-definitions>