├── .gitignore ├── .settings ├── org.eclipse.wst.jsdt.ui.superType.name ├── org.eclipse.wst.validation.prefs ├── org.eclipse.wst.jsdt.ui.superType.container ├── org.eclipse.m2e.core.prefs ├── org.eclipse.wst.common.project.facet.core.xml ├── .jsdtscope ├── org.eclipse.jdt.core.prefs └── org.eclipse.wst.common.component ├── WebContent ├── META-INF │ └── MANIFEST.MF ├── sandy.jpg ├── forest.jpg ├── WEB-INF │ ├── lib │ │ └── ojdbc8.jar │ └── web.xml ├── error.html ├── AdminLogin.html ├── UserLogin.html ├── ViewTrains.html ├── AdminHome.html ├── UserViewTrains.html ├── UserHome.html ├── UserRegister.html ├── CancleTrain.html ├── AdminSearchTrain.html ├── AdminUpdateTrain.html ├── SearchTrains.html ├── Availability.html ├── AddTrains.html ├── TrainBwStn.html ├── Fare.html ├── index.html ├── BookTrains.html ├── UserHome_Css.css └── Payment.html ├── Screenshots ├── Search.png ├── login.png ├── addtrains.png ├── booknow.png ├── userhome.png ├── TicketBook.png ├── fare result.png ├── fareenquiry.png ├── viewprofile.png ├── Availability.png ├── passwordchange.png └── registeruser.png ├── src ├── com │ └── shashi │ │ ├── constant │ │ ├── UserRole.java │ │ └── ResponseCode.java │ │ ├── beans │ │ ├── HistoryBean.java │ │ ├── AdminBean.java │ │ ├── TrainBean.java │ │ ├── UserBean.java │ │ ├── BookingDetails.java │ │ └── TrainException.java │ │ ├── service │ │ ├── BookingService.java │ │ ├── UserService.java │ │ ├── TrainService.java │ │ └── impl │ │ │ ├── BookingServiceImpl.java │ │ │ ├── TrainServiceImpl.java │ │ │ └── UserServiceImpl.java │ │ ├── servlets │ │ ├── FareEnqFwd.java │ │ ├── UserAvailFwd.java │ │ ├── AdminTrainUpdateFwd.java │ │ ├── UserSearchFwd.java │ │ ├── TrainBwStnFwd.java │ │ ├── BookTrainFwd.java │ │ ├── AddTrainFwd.java │ │ ├── AdminSearchTrainFwd.java │ │ ├── AdminCancleTrainFwd.java │ │ ├── UserLogoutServlet.java │ │ ├── BookTrainPayment.java │ │ ├── AdminLogoutServlet.java │ │ ├── UserHome.java │ │ ├── UserProfile.java │ │ ├── AdminLogin.java │ │ ├── UserLoginServlet.java │ │ ├── UserRegServlet.java │ │ ├── ChangeUserPassword.java │ │ ├── UpdateTrainSchedule.java │ │ ├── AdminCancleTrain.java │ │ ├── ViewUserProfile.java │ │ ├── UserViewLinkGet.java │ │ ├── EditUserProfile.java │ │ ├── UserSearchTrain.java │ │ ├── AdminAddTrain.java │ │ ├── TicketBookingHistory.java │ │ ├── AdminSearchTrain.java │ │ ├── AdminViewLinkFwd.java │ │ ├── BookTrainByRef.java │ │ ├── AdminViewTrainFwd.java │ │ ├── UserAvailServlet.java │ │ ├── AdminTrainUpdate.java │ │ ├── UserViewTrainFwd.java │ │ ├── UpdateUserProfile.java │ │ ├── FareEnq.java │ │ ├── ErrorHandlerServlet.java │ │ ├── TrainBwStn.java │ │ ├── ChangeUserPwd.java │ │ └── BookTrains.java │ │ └── utility │ │ ├── DBUtil.java │ │ └── TrainUtil.java └── application.properties ├── .classpath ├── .project ├── pom.xml ├── Dummy-Database.md └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /target/ 3 | -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /WebContent/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | disabled=06target 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /WebContent/sandy.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shashirajraja/Train-Ticket-Reservation-System/master/WebContent/sandy.jpg -------------------------------------------------------------------------------- /Screenshots/Search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shashirajraja/Train-Ticket-Reservation-System/master/Screenshots/Search.png -------------------------------------------------------------------------------- /Screenshots/login.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shashirajraja/Train-Ticket-Reservation-System/master/Screenshots/login.png -------------------------------------------------------------------------------- /WebContent/forest.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shashirajraja/Train-Ticket-Reservation-System/master/WebContent/forest.jpg -------------------------------------------------------------------------------- /Screenshots/addtrains.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shashirajraja/Train-Ticket-Reservation-System/master/Screenshots/addtrains.png -------------------------------------------------------------------------------- /Screenshots/booknow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shashirajraja/Train-Ticket-Reservation-System/master/Screenshots/booknow.png -------------------------------------------------------------------------------- /Screenshots/userhome.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shashirajraja/Train-Ticket-Reservation-System/master/Screenshots/userhome.png -------------------------------------------------------------------------------- /src/com/shashi/constant/UserRole.java: -------------------------------------------------------------------------------- 1 | package com.shashi.constant; 2 | 3 | public enum UserRole { 4 | ADMIN, CUSTOMER 5 | } 6 | -------------------------------------------------------------------------------- /.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /Screenshots/TicketBook.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shashirajraja/Train-Ticket-Reservation-System/master/Screenshots/TicketBook.png -------------------------------------------------------------------------------- /Screenshots/fare result.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shashirajraja/Train-Ticket-Reservation-System/master/Screenshots/fare result.png -------------------------------------------------------------------------------- /Screenshots/fareenquiry.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shashirajraja/Train-Ticket-Reservation-System/master/Screenshots/fareenquiry.png -------------------------------------------------------------------------------- /Screenshots/viewprofile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shashirajraja/Train-Ticket-Reservation-System/master/Screenshots/viewprofile.png -------------------------------------------------------------------------------- /Screenshots/Availability.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shashirajraja/Train-Ticket-Reservation-System/master/Screenshots/Availability.png -------------------------------------------------------------------------------- /Screenshots/passwordchange.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shashirajraja/Train-Ticket-Reservation-System/master/Screenshots/passwordchange.png -------------------------------------------------------------------------------- /Screenshots/registeruser.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shashirajraja/Train-Ticket-Reservation-System/master/Screenshots/registeruser.png -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/ojdbc8.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shashirajraja/Train-Ticket-Reservation-System/master/WebContent/WEB-INF/lib/ojdbc8.jar -------------------------------------------------------------------------------- /src/application.properties: -------------------------------------------------------------------------------- 1 | username=RESERVATION 2 | password=MANAGER 3 | driverName = oracle.jdbc.driver.OracleDriver 4 | connectionString=jdbc:oracle:thin:@localhost:1521:orcl -------------------------------------------------------------------------------- /WebContent/error.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | E-Trains 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/com/shashi/beans/HistoryBean.java: -------------------------------------------------------------------------------- 1 | package com.shashi.beans; 2 | 3 | public class HistoryBean extends BookingDetails { 4 | 5 | 6 | /** 7 | * 8 | */ 9 | private static final long serialVersionUID = 1L; 10 | 11 | private String transId; 12 | 13 | public String getTransId() { 14 | return transId; 15 | } 16 | 17 | public void setTransId(String transId) { 18 | this.transId = transId; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/com/shashi/service/BookingService.java: -------------------------------------------------------------------------------- 1 | package com.shashi.service; 2 | 3 | import java.util.List; 4 | 5 | import com.shashi.beans.HistoryBean; 6 | import com.shashi.beans.TrainException; 7 | 8 | public interface BookingService { 9 | 10 | public List getAllBookingsByCustomerId(String customerEmailId) throws TrainException; 11 | 12 | public HistoryBean createHistory(HistoryBean bookingDetails) throws TrainException; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/com/shashi/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.shashi.service; 2 | 3 | import java.util.List; 4 | 5 | import com.shashi.beans.UserBean; 6 | import com.shashi.beans.TrainException; 7 | 8 | public interface UserService { 9 | 10 | public UserBean getUserByEmailId(String userEmailId) throws TrainException; 11 | 12 | public List getAllUsers() throws TrainException; 13 | 14 | public String updateUser(UserBean customer); 15 | 16 | public String deleteUser(UserBean customer); 17 | 18 | public String registerUser(UserBean customer); 19 | 20 | public UserBean loginUser(String username, String password) throws TrainException; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/com/shashi/service/TrainService.java: -------------------------------------------------------------------------------- 1 | package com.shashi.service; 2 | 3 | import java.util.List; 4 | 5 | import com.shashi.beans.TrainBean; 6 | import com.shashi.beans.TrainException; 7 | 8 | public interface TrainService { 9 | 10 | public String addTrain(TrainBean train); 11 | 12 | public String deleteTrainById(String trainNo); 13 | 14 | public String updateTrain(TrainBean train); 15 | 16 | public TrainBean getTrainById(String trainNo) throws TrainException; 17 | 18 | public List getAllTrains() throws TrainException; 19 | 20 | public List getTrainsBetweenStations(String fromStation, String toStation) throws TrainException; 21 | } 22 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled 7 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 8 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 9 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore 10 | org.eclipse.jdt.core.compiler.release=disabled 11 | org.eclipse.jdt.core.compiler.source=1.8 12 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/FareEnqFwd.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.servlet.RequestDispatcher; 6 | import javax.servlet.ServletException; 7 | import javax.servlet.annotation.WebServlet; 8 | import javax.servlet.http.HttpServlet; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | 12 | import com.shashi.constant.UserRole; 13 | import com.shashi.utility.TrainUtil; 14 | 15 | @SuppressWarnings("serial") 16 | @WebServlet("/fareenqfwd") 17 | public class FareEnqFwd extends HttpServlet { 18 | protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 19 | res.setContentType("text/html"); 20 | 21 | TrainUtil.validateUserAuthorization(req, UserRole.CUSTOMER); 22 | 23 | RequestDispatcher rd = req.getRequestDispatcher("Fare.html"); 24 | rd.forward(req, res); 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/UserAvailFwd.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.servlet.RequestDispatcher; 6 | import javax.servlet.ServletException; 7 | import javax.servlet.annotation.WebServlet; 8 | import javax.servlet.http.HttpServlet; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | 12 | import com.shashi.constant.UserRole; 13 | import com.shashi.utility.TrainUtil; 14 | 15 | @SuppressWarnings("serial") 16 | @WebServlet("/useravailfwd") 17 | public class UserAvailFwd extends HttpServlet { 18 | protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 19 | res.setContentType("text/html"); 20 | TrainUtil.validateUserAuthorization(req, UserRole.CUSTOMER); 21 | RequestDispatcher rd = req.getRequestDispatcher("Availability.html"); 22 | rd.forward(req, res); 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/AdminTrainUpdateFwd.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.servlet.RequestDispatcher; 6 | import javax.servlet.ServletException; 7 | import javax.servlet.annotation.WebServlet; 8 | import javax.servlet.http.HttpServlet; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | 12 | @SuppressWarnings("serial") 13 | @WebServlet("/updatetrain") 14 | public class AdminTrainUpdateFwd extends HttpServlet { 15 | 16 | /** 17 | * 18 | * @param req 19 | * @param res 20 | * @throws IOException 21 | * @throws ServletException 22 | */ 23 | protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 24 | res.setContentType("text/html"); 25 | 26 | RequestDispatcher rd = req.getRequestDispatcher("AdminUpdateTrain.html"); 27 | rd.forward(req, res); 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/UserSearchFwd.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.servlet.RequestDispatcher; 6 | import javax.servlet.ServletException; 7 | import javax.servlet.annotation.WebServlet; 8 | import javax.servlet.http.HttpServlet; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | 12 | import com.shashi.constant.UserRole; 13 | import com.shashi.utility.TrainUtil; 14 | 15 | @SuppressWarnings("serial") 16 | @WebServlet("/usersearchtrain") 17 | public class UserSearchFwd extends HttpServlet { 18 | protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 19 | res.setContentType("text/html"); 20 | TrainUtil.validateUserAuthorization(req, UserRole.CUSTOMER); 21 | RequestDispatcher rd = req.getRequestDispatcher("SearchTrains.html"); 22 | rd.forward(req, res); 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/TrainBwStnFwd.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.servlet.RequestDispatcher; 6 | import javax.servlet.ServletException; 7 | import javax.servlet.annotation.WebServlet; 8 | import javax.servlet.http.HttpServlet; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | 12 | import com.shashi.constant.UserRole; 13 | import com.shashi.utility.TrainUtil; 14 | 15 | @SuppressWarnings("serial") 16 | @WebServlet("/trainbwstnfwd") 17 | public class TrainBwStnFwd extends HttpServlet { 18 | protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 19 | res.setContentType("text/html"); 20 | 21 | TrainUtil.validateUserAuthorization(req, UserRole.CUSTOMER); 22 | 23 | RequestDispatcher rd = req.getRequestDispatcher("TrainBwStn.html"); 24 | rd.forward(req, res); 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /WebContent/AdminLogin.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | E-Trains 6 | 7 | 8 | 9 |
10 |

National Ticket Booking Spot

11 | 19 |
20 | 21 |
Admin Login
22 |
23 |
UserName:
25 |
Password:
26 |

27 | 28 |
29 |
30 | 31 | 32 | -------------------------------------------------------------------------------- /WebContent/UserLogin.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | LOGIN 6 | 7 | 8 | 9 |
10 |

National Ticket Booking Spot

11 |
12 | 13 | Login as User 14 | 15 | 16 | New User Register 17 | 18 | 19 | Login as Admin 20 | 21 |
22 |
23 |
User Login
24 |
25 |
UserName:

Password:


29 | 30 |
31 |
32 | 33 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/BookTrainFwd.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.servlet.RequestDispatcher; 6 | import javax.servlet.ServletException; 7 | import javax.servlet.annotation.WebServlet; 8 | import javax.servlet.http.HttpServlet; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | 12 | import com.shashi.constant.UserRole; 13 | import com.shashi.utility.TrainUtil; 14 | 15 | @WebServlet("/booktrainfwd") 16 | public class BookTrainFwd extends HttpServlet { 17 | /** 18 | * 19 | */ 20 | private static final long serialVersionUID = 1L; 21 | 22 | public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 23 | res.setContentType("text/html"); 24 | TrainUtil.validateUserAuthorization(req, UserRole.CUSTOMER); 25 | 26 | RequestDispatcher rd = req.getRequestDispatcher("BookTrains.html"); 27 | rd.forward(req, res); 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/AddTrainFwd.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.servlet.RequestDispatcher; 6 | import javax.servlet.ServletException; 7 | import javax.servlet.annotation.WebServlet; 8 | import javax.servlet.http.HttpServlet; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | 12 | import com.shashi.constant.UserRole; 13 | import com.shashi.utility.TrainUtil; 14 | 15 | @SuppressWarnings("serial") 16 | @WebServlet("/addtrainfwd") 17 | public class AddTrainFwd extends HttpServlet { 18 | 19 | /** 20 | * 21 | * @param req 22 | * @param res 23 | * @throws IOException 24 | * @throws ServletException 25 | */ 26 | protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 27 | res.setContentType("text/html"); 28 | TrainUtil.validateUserAuthorization(req, UserRole.ADMIN); 29 | RequestDispatcher rd = req.getRequestDispatcher("AddTrains.html"); 30 | rd.forward(req, res); 31 | 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/AdminSearchTrainFwd.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.servlet.RequestDispatcher; 6 | import javax.servlet.ServletException; 7 | import javax.servlet.annotation.WebServlet; 8 | import javax.servlet.http.HttpServlet; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | 12 | import com.shashi.constant.UserRole; 13 | import com.shashi.utility.TrainUtil; 14 | 15 | @SuppressWarnings("serial") 16 | @WebServlet("/adminsearchtrainfwd") 17 | public class AdminSearchTrainFwd extends HttpServlet { 18 | 19 | /** 20 | * 21 | * @param req 22 | * @param res 23 | * @throws IOException 24 | * @throws ServletException 25 | */ 26 | protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 27 | res.setContentType("text/html"); 28 | TrainUtil.validateUserAuthorization(req, UserRole.ADMIN); 29 | RequestDispatcher rd = req.getRequestDispatcher("AdminSearchTrain.html"); 30 | rd.forward(req, res); 31 | 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/AdminCancleTrainFwd.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.servlet.RequestDispatcher; 6 | import javax.servlet.ServletException; 7 | import javax.servlet.annotation.WebServlet; 8 | import javax.servlet.http.HttpServlet; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | 12 | import com.shashi.constant.UserRole; 13 | import com.shashi.utility.TrainUtil; 14 | 15 | @WebServlet("/cancletrainfwd") 16 | public class AdminCancleTrainFwd extends HttpServlet { 17 | /** 18 | * 19 | */ 20 | private static final long serialVersionUID = 1L; 21 | 22 | /** 23 | * 24 | * @param req 25 | * @param res 26 | * @throws IOException 27 | * @throws ServletException 28 | */ 29 | protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 30 | res.setContentType("text/html"); 31 | TrainUtil.validateUserAuthorization(req, UserRole.ADMIN); 32 | RequestDispatcher rd = req.getRequestDispatcher("CancleTrain.html"); 33 | rd.forward(req, res); 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | TrainBook 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.wst.common.project.facet.core.builder 15 | 16 | 17 | 18 | 19 | org.eclipse.wst.validation.validationbuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.m2e.core.maven2Builder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.m2e.core.maven2Nature 31 | org.eclipse.jem.workbench.JavaEMFNature 32 | org.eclipse.wst.common.modulecore.ModuleCoreNature 33 | org.eclipse.wst.common.project.facet.core.nature 34 | org.eclipse.jdt.core.javanature 35 | org.eclipse.wst.jsdt.core.jsNature 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/com/shashi/utility/DBUtil.java: -------------------------------------------------------------------------------- 1 | package com.shashi.utility; 2 | 3 | import java.sql.Connection; 4 | import java.sql.DriverManager; 5 | import java.sql.SQLException; 6 | import java.util.ResourceBundle; 7 | 8 | import com.shashi.beans.TrainException; 9 | import com.shashi.constant.ResponseCode; 10 | 11 | public class DBUtil { 12 | private static Connection con; 13 | 14 | static { 15 | 16 | ResourceBundle rb = ResourceBundle.getBundle("application"); 17 | 18 | try { 19 | Class.forName(rb.getString("driverName")); 20 | } catch (ClassNotFoundException e) { 21 | e.printStackTrace(); 22 | } 23 | 24 | try { 25 | System.out.println(rb.getString("connectionString")); 26 | System.out.println(rb.getString("username")); 27 | System.out.println(rb.getString("password")); 28 | con = DriverManager.getConnection(rb.getString("connectionString"), rb.getString("username"), 29 | rb.getString("password")); 30 | System.out.println("Connection Success!!"); 31 | } catch (SQLException e) { 32 | 33 | e.printStackTrace(); 34 | } 35 | } 36 | 37 | public static Connection getConnection() throws TrainException { 38 | if (con == null) 39 | throw new TrainException(ResponseCode.DATABASE_CONNECTION_FAILURE); 40 | return con; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/com/shashi/beans/AdminBean.java: -------------------------------------------------------------------------------- 1 | package com.shashi.beans; 2 | 3 | import java.io.Serializable; 4 | 5 | public class AdminBean implements Serializable { 6 | /** 7 | * 8 | */ 9 | private static final long serialVersionUID = 1L; 10 | private String fName; 11 | private String lName; 12 | private String pWord; 13 | private String addR; 14 | private String mailId; 15 | private long phNo; 16 | 17 | public void setPWord(String pWord) { 18 | this.pWord = pWord; 19 | } 20 | 21 | public String getPWord() { 22 | return pWord; 23 | } 24 | 25 | public void setFName(String fName) { 26 | this.fName = fName; 27 | } 28 | 29 | public String getFName() { 30 | return fName; 31 | } 32 | 33 | public void setLName(String lName) { 34 | this.lName = lName; 35 | } 36 | 37 | public String getLName() { 38 | return lName; 39 | } 40 | 41 | public void setAddr(String addR) { 42 | this.addR = addR; 43 | } 44 | 45 | public String getAddr() { 46 | return addR; 47 | } 48 | 49 | public void setMailId(String mailId) { 50 | this.mailId = mailId; 51 | } 52 | 53 | public String getMailId() { 54 | return mailId; 55 | } 56 | 57 | public void setPhNo(long phNo) { 58 | this.phNo = phNo; 59 | } 60 | 61 | public long getPhNo() { 62 | return phNo; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/com/shashi/beans/TrainBean.java: -------------------------------------------------------------------------------- 1 | package com.shashi.beans; 2 | 3 | import java.io.Serializable; 4 | 5 | public class TrainBean implements Serializable { 6 | 7 | /** 8 | * 9 | */ 10 | private static final long serialVersionUID = 1L; 11 | 12 | private Long tr_no; 13 | private String tr_name; 14 | private String from_stn; 15 | private String to_stn; 16 | private Integer seats; 17 | private Double fare; 18 | 19 | public Long getTr_no() { 20 | return tr_no; 21 | } 22 | 23 | public void setTr_no(Long tr_no) { 24 | this.tr_no = tr_no; 25 | } 26 | 27 | public String getTr_name() { 28 | return tr_name; 29 | } 30 | 31 | public void setTr_name(String tr_name) { 32 | this.tr_name = tr_name; 33 | } 34 | 35 | public String getFrom_stn() { 36 | return from_stn; 37 | } 38 | 39 | public void setFrom_stn(String from_stn) { 40 | this.from_stn = from_stn; 41 | } 42 | 43 | public String getTo_stn() { 44 | return to_stn; 45 | } 46 | 47 | public void setTo_stn(String to_stn) { 48 | this.to_stn = to_stn; 49 | } 50 | 51 | public Integer getSeats() { 52 | return seats; 53 | } 54 | 55 | public void setSeats(Integer seats) { 56 | this.seats = seats; 57 | } 58 | 59 | public Double getFare() { 60 | return fare; 61 | } 62 | 63 | public void setFare(Double fare) { 64 | this.fare = fare; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/com/shashi/beans/UserBean.java: -------------------------------------------------------------------------------- 1 | package com.shashi.beans; 2 | 3 | import java.io.Serializable; 4 | 5 | public class UserBean implements Serializable { 6 | /** 7 | * 8 | */ 9 | private static final long serialVersionUID = 1L; 10 | 11 | private String fName; 12 | private String lName; 13 | private String pWord; 14 | private String addR; 15 | private String mailId; 16 | private long phNo; 17 | 18 | public void setPWord(String pWord) { 19 | this.pWord = pWord; 20 | } 21 | 22 | public String getPWord() { 23 | return pWord; 24 | } 25 | 26 | public void setFName(String fName) { 27 | this.fName = fName; 28 | } 29 | 30 | public String getFName() { 31 | return fName; 32 | } 33 | 34 | public void setLName(String lName) { 35 | this.lName = lName; 36 | } 37 | 38 | public String getLName() { 39 | return lName; 40 | } 41 | 42 | public void setAddr(String addR) { 43 | this.addR = addR; 44 | } 45 | 46 | public String getAddr() { 47 | return addR; 48 | } 49 | 50 | public void setMailId(String mailId) { 51 | this.mailId = mailId; 52 | } 53 | 54 | public String getMailId() { 55 | return mailId; 56 | } 57 | 58 | public void setPhNo(long phNo) { 59 | this.phNo = phNo; 60 | } 61 | 62 | public long getPhNo() { 63 | return phNo; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /WebContent/ViewTrains.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Trains 6 | 7 | 8 | 9 |
10 |

National Ticket Booking Spot

11 |
12 | 15 |
16 |
17 | 20 |
21 |
22 | 25 |
26 | 27 |
28 | 31 |
32 |
33 | 36 |
37 |
38 | 41 |
42 |
43 | 46 |
47 | 48 |
49 | 50 |
51 |
52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /WebContent/AdminHome.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | E-Trains 6 | 7 | 8 | 9 |
10 |

National Ticket Booking Spot

11 |
12 | 15 |
16 |
17 | 20 |
21 |
22 | 25 |
26 | 27 |
28 | 31 |
32 |
33 | 36 |
37 |
38 | 41 |
42 |
43 | 46 |
47 |
48 | 49 |
50 | 52 |
53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/UserLogoutServlet.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.RequestDispatcher; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.annotation.WebServlet; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import com.shashi.constant.UserRole; 14 | import com.shashi.utility.TrainUtil; 15 | 16 | @SuppressWarnings("serial") 17 | @WebServlet("/userlogout") 18 | public class UserLogoutServlet extends HttpServlet { 19 | protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { 20 | res.setContentType("text/html"); 21 | PrintWriter pw = res.getWriter(); 22 | 23 | if (TrainUtil.isLoggedIn(req, UserRole.CUSTOMER)) { 24 | TrainUtil.logout(res); 25 | RequestDispatcher rd = req.getRequestDispatcher("UserLogin.html"); 26 | rd.include(req, res); 27 | pw.println("
You have been successfully logged out !
"); 28 | } else { 29 | RequestDispatcher rd = req.getRequestDispatcher("UserLogin.html"); 30 | rd.include(req, res); 31 | 32 | pw.println("
You are Already Logged Out !
"); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/BookTrainPayment.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.servlet.RequestDispatcher; 6 | import javax.servlet.ServletContext; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.annotation.WebServlet; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import com.shashi.constant.UserRole; 14 | import com.shashi.utility.TrainUtil; 15 | 16 | @WebServlet("/payment") 17 | public class BookTrainPayment extends HttpServlet { 18 | /** 19 | * 20 | */ 21 | private static final long serialVersionUID = 1L; 22 | 23 | public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 24 | res.setContentType("text/html"); 25 | TrainUtil.validateUserAuthorization(req, UserRole.CUSTOMER); 26 | 27 | int seat = Integer.parseInt(req.getParameter("seats")); 28 | String trainNo = req.getParameter("trainnumber"); 29 | String journeyDate = req.getParameter("journeydate"); 30 | String seatClass = req.getParameter("class"); 31 | ServletContext sct = req.getServletContext(); 32 | sct.setAttribute("seats", seat); 33 | sct.setAttribute("trainnumber", trainNo); 34 | sct.setAttribute("journeydate", journeyDate); 35 | sct.setAttribute("class", seatClass); 36 | RequestDispatcher rd = req.getRequestDispatcher("Payment.html"); 37 | rd.forward(req, res); 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /WebContent/UserViewTrains.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | View Trains 6 | 7 | 8 | 9 |
10 |

National Ticket Booking Spot

11 |
12 | 15 |
16 |
17 | 20 |
21 |
22 | 25 |
26 |
27 | 30 |
31 |
32 | 35 |
36 |
37 | 40 |
41 |
42 | 45 |
46 |
47 | 50 |
51 |
52 | 55 |
56 |
57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /WebContent/UserHome.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | E-Trains 6 | 7 | 9 | 10 | 11 |
12 |

National Ticket Booking Spot

13 |
14 | 17 |
18 |
19 | 22 |
23 |
24 | 27 |
28 |
29 | 32 |
33 |
34 | 37 |
38 |
39 | 42 |
43 |
44 | 47 |
48 |
49 | 52 |
53 |
54 | 57 |
58 |
59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/AdminLogoutServlet.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.RequestDispatcher; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.annotation.WebServlet; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import com.shashi.constant.UserRole; 14 | import com.shashi.utility.TrainUtil; 15 | 16 | @SuppressWarnings("serial") 17 | @WebServlet("/adminlogout") 18 | public class AdminLogoutServlet extends HttpServlet { 19 | 20 | /** 21 | * 22 | * @param req 23 | * @param res 24 | * @throws ServletException 25 | * @throws IOException 26 | */ 27 | protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { 28 | res.setContentType("text/html"); 29 | PrintWriter pw = res.getWriter(); 30 | if (TrainUtil.isLoggedIn(req, UserRole.ADMIN)) { 31 | TrainUtil.logout(res); 32 | RequestDispatcher rd = req.getRequestDispatcher("AdminLogin.html"); 33 | rd.include(req, res); 34 | pw.println("
You have been successfully logged out !
"); 35 | } else { 36 | RequestDispatcher rd = req.getRequestDispatcher("AdminLogin.html"); 37 | rd.include(req, res); 38 | pw.println("
You are Already Logged Out !
"); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /WebContent/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 9 | 10 | 11 | ErrorHandlerServlet 12 | com.shashi.servlets.ErrorHandlerServlet 13 | 14 | 15 | ErrorHandlerServlet 16 | /error 17 | 18 | 19 | 20 | 404 21 | /error 22 | 23 | 24 | 405 25 | /error 26 | 27 | 28 | 29 | 30 | 31 | javax.servlet.ServletException 32 | 33 | /error 34 | 35 | 36 | 37 | java.lang.Throwable 38 | /error 39 | 40 | 41 | 42 | UserLogin.html 43 | 44 | -------------------------------------------------------------------------------- /src/com/shashi/beans/BookingDetails.java: -------------------------------------------------------------------------------- 1 | package com.shashi.beans; 2 | 3 | import java.io.Serializable; 4 | 5 | public class BookingDetails implements Serializable { 6 | /** 7 | * 8 | */ 9 | private static final long serialVersionUID = 1L; 10 | private String mailId; 11 | private String tr_no; 12 | private String date; 13 | private String from_stn; 14 | private String to_stn; 15 | private int seats; 16 | private Double amount; 17 | 18 | public String getMailId() { 19 | return mailId; 20 | } 21 | 22 | public void setMailId(String mailId) { 23 | this.mailId = mailId; 24 | } 25 | 26 | public String getTr_no() { 27 | return tr_no; 28 | } 29 | 30 | public void setTr_no(String tr_no) { 31 | this.tr_no = tr_no; 32 | } 33 | 34 | public String getDate() { 35 | return date; 36 | } 37 | 38 | public void setDate(String date) { 39 | this.date = date; 40 | } 41 | 42 | public String getFrom_stn() { 43 | return from_stn; 44 | } 45 | 46 | public void setFrom_stn(String from_stn) { 47 | this.from_stn = from_stn; 48 | } 49 | 50 | public String getTo_stn() { 51 | return to_stn; 52 | } 53 | 54 | public void setTo_stn(String to_stn) { 55 | this.to_stn = to_stn; 56 | } 57 | 58 | public int getSeats() { 59 | return seats; 60 | } 61 | 62 | public void setSeats(int seats) { 63 | this.seats = seats; 64 | } 65 | 66 | public Double getAmount() { 67 | return amount; 68 | } 69 | 70 | public void setAmount(Double amount) { 71 | this.amount = amount; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/com/shashi/constant/ResponseCode.java: -------------------------------------------------------------------------------- 1 | package com.shashi.constant; 2 | 3 | import java.util.Arrays; 4 | import java.util.Optional; 5 | 6 | public enum ResponseCode { 7 | 8 | SUCCESS(200, "OK"), 9 | FAILURE(422, "Unprocessible Entity, Failed to Process"), 10 | NO_CONTENT(204, "No Items Found"), 11 | PAGE_NOT_FOUND(404, "The Page You are Searching For is Not available"), 12 | ACCESS_DENIED(403, "Please Login First to continue"), 13 | BAD_REQUEST(400, "Bad Request, Please Try Again"), 14 | UNAUTHORIZED(401,"Invalid Credentials, Try Again"), 15 | SESSION_EXPIRED(401, "Session Expired, Login Again to Continue"), 16 | INTERNAL_SERVER_ERROR(500, "Internal Server Error, Try Again!!"), 17 | DATABASE_CONNECTION_FAILURE(406, 18 | "Unable to Connect to DB, Please Check your db credentials in application.properties"), 19 | METHOD_NOT_ALLOWED(405, "Requested HTTP method is not supported by this URL"), 20 | 21 | ; 22 | 23 | private final String message; 24 | private final int code; 25 | 26 | ResponseCode(int code, String message) { 27 | this.message = message; 28 | this.code = code; 29 | } 30 | 31 | public String getMessage() { 32 | return message; 33 | } 34 | 35 | public int getCode() { 36 | return code; 37 | } 38 | 39 | // Reverse lookup methods 40 | public static Optional getMessageByStatusCode(int statusCode) { 41 | return Arrays.stream(ResponseCode.values()) 42 | .filter(error -> error.getCode() == statusCode) 43 | .findFirst(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/UserHome.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.RequestDispatcher; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.annotation.WebServlet; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import com.shashi.constant.UserRole; 14 | import com.shashi.utility.TrainUtil; 15 | 16 | @SuppressWarnings("serial") 17 | @WebServlet("/userhome") 18 | public class UserHome extends HttpServlet { 19 | protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 20 | res.setContentType("text/html"); 21 | PrintWriter pw = res.getWriter(); 22 | TrainUtil.validateUserAuthorization(req, UserRole.CUSTOMER); 23 | RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); 24 | rd.include(req, res); 25 | pw.println("
" + " " + " Hello " + TrainUtil.getCurrentUserName(req) 26 | + " ! Welcome to our new NITRTC Website" + " " + "
"); 27 | pw.println("
User Home
"); 28 | pw.println("
Hello " + TrainUtil.getCurrentUserName(req) 29 | + " ! Good to See You here.
Here you can Check up the train " 30 | + "details, train schedule, fare Enquiry and many more information.
Just go to the Side Menu Links and " 31 | + "Explore the Advantages.

Thanks For Being Connected with us!" + "
"); 32 | 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /WebContent/UserRegister.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | LOGIN 6 | 7 | 8 | 9 |
10 |

National Ticket Booking Spot

11 | 19 |
20 | 21 | 22 | 23 | 24 |
New User Registration
25 | 26 | 27 | 28 | 29 | 44 | 45 | 46 |
30 |
31 | Email Id :

33 | Password :
34 |
FirstName:
35 |
Last Name:
36 |
Address :
37 |
Phone No :
38 |
Photo :
39 |
42 |
43 |
47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /WebContent/CancleTrain.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | E-Trains 6 | 7 | 8 | 9 |
10 |

National Ticket Booking Spot

11 |
12 | 15 |
16 |
17 | 20 |
21 |
22 | 25 |
26 | 27 |
28 | 31 |
32 |
33 | 36 |
37 |
38 | 41 |
42 |
43 | 46 |
47 |
48 | 49 |
50 | 52 |
53 | 54 |
55 | 56 |
57 |
58 | Train Number:
59 |
60 |
61 |
62 | 63 | 64 | -------------------------------------------------------------------------------- /WebContent/AdminSearchTrain.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | E-Trains 6 | 7 | 8 | 9 |
10 |

National Ticket Booking Spot

11 |
12 | 15 |
16 |
17 | 20 |
21 |
22 | 25 |
26 | 27 |
28 | 31 |
32 |
33 | 36 |
37 |
38 | 41 |
42 |
43 | 46 |
47 |
48 | 49 |
50 | 52 |
53 |
54 | 55 |
56 |
57 |
TrainNumber:
58 |

59 |
60 |
61 | 62 | -------------------------------------------------------------------------------- /src/com/shashi/beans/TrainException.java: -------------------------------------------------------------------------------- 1 | package com.shashi.beans; 2 | 3 | import java.io.IOException; 4 | 5 | import com.shashi.constant.ResponseCode; 6 | 7 | public class TrainException extends IOException { 8 | 9 | /** 10 | * 11 | */ 12 | private static final long serialVersionUID = 1L; 13 | 14 | private String errorCode; 15 | private String errorMessage; 16 | private int statusCode; 17 | 18 | public TrainException(ResponseCode errorCodes) { 19 | super(errorCodes.getMessage()); 20 | this.statusCode = errorCodes.getCode(); 21 | this.errorMessage = errorCodes.getMessage(); 22 | this.setErrorCode(errorCodes.name()); 23 | } 24 | 25 | public TrainException(String errorMessage) { 26 | super(errorMessage); 27 | this.errorCode = "BAD_REQUEST"; 28 | this.setStatusCode(400); 29 | this.errorMessage = errorMessage; 30 | } 31 | 32 | public TrainException(int statusCode, String errorCode, String errorMessage) { 33 | super(errorMessage); 34 | this.statusCode = statusCode; 35 | this.errorCode = errorCode; 36 | this.errorMessage = errorMessage; 37 | } 38 | 39 | public String getErrorCode() { 40 | return errorCode; 41 | } 42 | 43 | public void setErrorCode(String errorCode) { 44 | this.errorCode = errorCode; 45 | } 46 | 47 | public String getErrorMessage() { 48 | return errorMessage; 49 | } 50 | 51 | public void setErrorMessage(String errorMessage) { 52 | this.errorMessage = errorMessage; 53 | } 54 | 55 | public int getStatusCode() { 56 | return statusCode; 57 | } 58 | 59 | public void setStatusCode(int statusCode) { 60 | this.statusCode = statusCode; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /WebContent/AdminUpdateTrain.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | E-Trains 6 | 7 | 8 | 9 |
10 |

National Ticket Booking Spot

11 |
12 | 15 |
16 |
17 | 20 |
21 |
22 | 25 |
26 | 27 |
28 | 31 |
32 |
33 | 36 |
37 |
38 | 41 |
42 |
43 | 46 |
47 |
48 | 49 |
50 | 52 |
53 | 54 |
55 | 56 |
57 |
58 |
TrainNumber:
59 |

60 |
61 |
62 | 63 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/UserProfile.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.RequestDispatcher; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.annotation.WebServlet; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import com.shashi.constant.UserRole; 14 | import com.shashi.utility.TrainUtil; 15 | 16 | @SuppressWarnings("serial") 17 | @WebServlet("/userprofile") 18 | public class UserProfile extends HttpServlet { 19 | protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 20 | res.setContentType("text/html"); 21 | PrintWriter pw = res.getWriter(); 22 | 23 | TrainUtil.validateUserAuthorization(req, UserRole.CUSTOMER); 24 | 25 | RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); 26 | rd.include(req, res); 27 | pw.println("
" + " " + " Hello " + TrainUtil.getCurrentUserName(req) 28 | + " ! Welcome to our new NITRTC Website" + " " + "
"); 29 | pw.println("
View Profile " 30 | + "Edit Profile " 31 | + "Change Password" + "
"); 32 | pw.println("
Hey ! " + TrainUtil.getCurrentUserName(req) 33 | + ",Welcome to NITRTC

Here You can Edit,View Your Profile and change your PassWord.
" 34 | + "
Thanks For Being Connected With Us!" + "
"); 35 | 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /WebContent/SearchTrains.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | E-Trains 6 | 7 | 8 | 9 |
10 |

National Ticket Booking Spot

11 |
12 | 15 |
16 |
17 | 20 |
21 |
22 | 25 |
26 |
27 | 30 |
31 |
32 | 35 |
36 |
37 | 40 |
41 |
42 | 45 |
46 |
47 | 50 |
51 |
52 | 55 |
56 |
57 | 58 |
59 | 60 |
61 |
62 | TrainNumber:
63 |

64 |
65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /WebContent/Availability.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ETrains 6 | 7 | 9 | 10 | 11 |
12 |

National Ticket Booking Spot

13 |
14 | 17 |
18 |
19 | 22 |
23 |
24 | 27 |
28 |
29 | 32 |
33 |
34 | 37 |
38 |
39 | 42 |
43 |
44 | 47 |
48 |
49 | 52 |
53 |
54 | 57 |
58 |
59 | 60 |
61 | 62 |
63 |
64 | TrainNumber:

65 |
66 |
67 |
68 | 69 | 70 | -------------------------------------------------------------------------------- /WebContent/AddTrains.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | E-Trains 6 | 7 | 8 | 9 |
10 |

National Ticket Booking Spot

11 |
12 | 15 |
16 |
17 | 20 |
21 |
22 | 25 |
26 | 27 |
28 | 31 |
32 |
33 | 36 |
37 |
38 | 41 |
42 |
43 | 46 |
47 |
48 |
49 | 50 |
51 |
52 |
Train Number:
53 |
Train Name:
54 |
From Station:
55 |
To Station:
56 |
Available:
57 |
Fare (INR):
58 |
59 |
60 |
61 | 62 | -------------------------------------------------------------------------------- /WebContent/TrainBwStn.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | E-Trains 6 | 7 | 8 | 9 |
10 |

National Ticket Booking Spot

11 |
12 | 15 |
16 |
17 | 20 |
21 |
22 | 25 |
26 |
27 | 30 |
31 |
32 | 35 |
36 |
37 | 40 |
41 |
42 | 45 |
46 |
47 | 50 |
51 |
52 | 55 |
56 |
57 |
58 | 59 |
60 |
61 | From Station:
62 |
To Station:
63 |

64 |
65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /WebContent/Fare.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | E-Trains 6 | 7 | 9 | 10 | 11 |
12 |

National Ticket Booking Spot

13 |
14 | 17 |
18 |
19 | 22 |
23 |
24 | 27 |
28 |
29 | 32 |
33 |
34 | 37 |
38 |
39 | 42 |
43 |
44 | 47 |
48 |
49 | 52 |
53 |
54 | 57 |
58 |
59 | 60 | 61 |
62 | 63 |
64 |
65 | From Station:
66 |
To Station:
67 |

68 |
69 |
70 | 71 | 72 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/AdminLogin.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.RequestDispatcher; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.annotation.WebServlet; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import com.shashi.beans.TrainException; 14 | import com.shashi.constant.UserRole; 15 | import com.shashi.utility.TrainUtil; 16 | 17 | @SuppressWarnings("serial") 18 | @WebServlet("/adminlogin") 19 | public class AdminLogin extends HttpServlet { 20 | 21 | /** 22 | * 23 | * @param req 24 | * @param res 25 | * @throws IOException 26 | * @throws ServletException 27 | */ 28 | protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 29 | PrintWriter pw = res.getWriter(); 30 | res.setContentType("text/html"); 31 | String uName = req.getParameter("uname"); 32 | String pWord = req.getParameter("pword"); 33 | try { 34 | String message = TrainUtil.login(req, res, UserRole.ADMIN, uName, pWord); 35 | if ("SUCCESS".equalsIgnoreCase(message)) { 36 | 37 | RequestDispatcher rd = req.getRequestDispatcher("AdminHome.html"); 38 | rd.include(req, res); 39 | pw.println("
Hello, " + uName + " ! Welcome
"); 40 | pw.println("
Hi ! Here You can Manage Train Information as per Your Requirement
"); 41 | 42 | } else { 43 | RequestDispatcher rd = req.getRequestDispatcher("AdminLogin.html"); 44 | rd.include(req, res); 45 | pw.println("
" + message + "
"); 46 | 47 | } 48 | } catch (Exception e) { 49 | throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /WebContent/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | E-Trains 6 | 7 | 8 | 9 |
10 |

National Ticket Booking Spot

11 |
12 | 15 |
16 |
17 | 20 |
21 |
22 | 25 |
26 |
27 | 30 |
31 |
32 | 35 |
36 |
37 | 40 |
41 |
42 | 45 |
46 |
47 | 50 |
51 |
52 | 55 |
56 |
57 |
User Login
58 |
59 |
UserName:

Password:


63 | 64 |
65 |
66 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/UserLoginServlet.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.RequestDispatcher; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.annotation.WebServlet; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import com.shashi.constant.ResponseCode; 14 | import com.shashi.constant.UserRole; 15 | import com.shashi.utility.TrainUtil; 16 | 17 | @WebServlet("/userlogin") 18 | public class UserLoginServlet extends HttpServlet { 19 | /** 20 | * 21 | */ 22 | private static final long serialVersionUID = 1L; 23 | 24 | protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 25 | PrintWriter pw = res.getWriter(); 26 | res.setContentType("text/html"); 27 | String uName = req.getParameter("uname"); 28 | String pWord = req.getParameter("pword"); 29 | 30 | String responseMsg = TrainUtil.login(req, res, UserRole.CUSTOMER, uName, pWord); 31 | if (ResponseCode.SUCCESS.toString().equalsIgnoreCase(responseMsg)) { 32 | RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); 33 | rd.include(req, res); 34 | pw.println("
Hello " + uName 35 | + " ! Welcome to our new NITRTC Website
"); 36 | pw.println("
Hello " + uName 37 | + " ! Good to See You here.
Here you can Check up the train " 38 | + "details and train schedule,fare Enquiry and many more information.
Just go to the Side Menu Links and " 39 | + "Explore the Advantages.

Thanks For Being Connected with us!" + "
"); 40 | 41 | } else { 42 | RequestDispatcher rd = req.getRequestDispatcher("UserLogin.html"); 43 | rd.include(req, res); 44 | 45 | pw.println("
" + responseMsg + "
"); 46 | 47 | } 48 | 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/UserRegServlet.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.RequestDispatcher; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.annotation.WebServlet; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import com.shashi.beans.TrainException; 14 | import com.shashi.beans.UserBean; 15 | import com.shashi.constant.UserRole; 16 | import com.shashi.service.UserService; 17 | import com.shashi.service.impl.UserServiceImpl; 18 | 19 | @SuppressWarnings("serial") 20 | @WebServlet("/userreg") 21 | public class UserRegServlet extends HttpServlet { 22 | 23 | private UserService userService = new UserServiceImpl(UserRole.CUSTOMER); 24 | 25 | protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 26 | res.setContentType("text/html"); 27 | PrintWriter pw = res.getWriter(); 28 | try { 29 | UserBean user = new UserBean(); 30 | user.setMailId(req.getParameter("mailid")); 31 | user.setPWord(req.getParameter("pword")); 32 | user.setFName(req.getParameter("firstname")); 33 | user.setLName(req.getParameter("lastname")); 34 | user.setAddr(req.getParameter("address")); 35 | user.setPhNo(Long.parseLong(req.getParameter("phoneno"))); 36 | 37 | String message = userService.registerUser(user); 38 | if ("SUCCESS".equalsIgnoreCase(message)) { 39 | RequestDispatcher rd = req.getRequestDispatcher("UserLogin.html"); 40 | rd.include(req, res); 41 | pw.println("
User Registered Successfully !
"); 42 | 43 | } else { 44 | RequestDispatcher rd = req.getRequestDispatcher("UserRegister.html"); 45 | rd.include(req, res); 46 | pw.println("
" + message + "
"); 47 | 48 | } 49 | 50 | } catch (Exception e) { 51 | throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); 52 | } 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/ChangeUserPassword.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.RequestDispatcher; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.annotation.WebServlet; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import com.shashi.constant.UserRole; 14 | import com.shashi.utility.TrainUtil; 15 | 16 | //import com.shashi.beans.UserBean; 17 | 18 | @SuppressWarnings("serial") 19 | @WebServlet("/changeuserpassword") 20 | public class ChangeUserPassword extends HttpServlet { 21 | protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 22 | res.setContentType("text/html"); 23 | PrintWriter pw = res.getWriter(); 24 | TrainUtil.validateUserAuthorization(req, UserRole.CUSTOMER); 25 | 26 | RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); 27 | rd.include(req, res); 28 | pw.println("
" + " " + " Hello " + TrainUtil.getCurrentUserName(req) 29 | + " ! Welcome to our new NITRTC Website" + " " + "
"); 30 | pw.println("
View Profile " 31 | + "Edit Profile " 32 | + "Change Password" + "
"); 33 | pw.println("
Password Change
"); 34 | pw.println("
" + "" 35 | + "" 36 | + "" 37 | + "" 38 | + "" 39 | + "
User Name :
Old Password :
New Password :
" + "
"); 40 | 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /WebContent/BookTrains.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | E-Trains 6 | 7 | 9 | 10 | 11 |
12 |

National Ticket Booking Spot

13 |
14 | 17 |
18 |
19 | 22 |
23 |
24 | 27 |
28 |
29 | 32 |
33 |
34 | 37 |
38 |
39 | 42 |
43 |
44 | 47 |
48 |
49 | 52 |
53 |
54 | 57 |
58 |
59 | 60 |
61 | 63 |
64 | 65 |
66 | 67 |
68 |
69 | 73 |
74 |
75 | TrainNumber:

76 | No of seats:


78 |
79 |
80 | 81 | 82 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/UpdateTrainSchedule.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.RequestDispatcher; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.annotation.WebServlet; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import com.shashi.beans.TrainBean; 14 | import com.shashi.beans.TrainException; 15 | import com.shashi.service.TrainService; 16 | import com.shashi.service.impl.TrainServiceImpl; 17 | 18 | @SuppressWarnings("serial") 19 | @WebServlet("/updatetrainschedule") 20 | public class UpdateTrainSchedule extends HttpServlet { 21 | 22 | private TrainService trainService = new TrainServiceImpl(); 23 | 24 | protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 25 | res.setContentType("text/html"); 26 | PrintWriter pw = res.getWriter(); 27 | 28 | try { 29 | 30 | TrainBean train = new TrainBean(); 31 | train.setTr_no(Long.parseLong(req.getParameter("trainno"))); 32 | train.setTr_name(req.getParameter("trainname")); 33 | train.setFrom_stn(req.getParameter("fromstation")); 34 | train.setTo_stn(req.getParameter("tostation")); 35 | train.setSeats(Integer.parseInt(req.getParameter("available"))); 36 | train.setFare(Double.parseDouble(req.getParameter("fare"))); 37 | 38 | String message = trainService.updateTrain(train); 39 | if ("SUCCESS".equalsIgnoreCase(message)) { 40 | RequestDispatcher rd = req.getRequestDispatcher("AdminUpdateTrain.html"); 41 | rd.include(req, res); 42 | pw.println("
Train Updated Successfully!
"); 43 | } else { 44 | RequestDispatcher rd = req.getRequestDispatcher("AdminUpdateTrain.html"); 45 | rd.include(req, res); 46 | pw.println("
Error in filling the train Detail
"); 47 | } 48 | } catch (Exception e) { 49 | throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); 50 | } 51 | 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/AdminCancleTrain.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.RequestDispatcher; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.annotation.WebServlet; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import com.shashi.beans.TrainException; 14 | import com.shashi.constant.ResponseCode; 15 | import com.shashi.constant.UserRole; 16 | import com.shashi.service.TrainService; 17 | import com.shashi.service.impl.TrainServiceImpl; 18 | import com.shashi.utility.TrainUtil; 19 | 20 | @WebServlet("/admincancletrain") 21 | public class AdminCancleTrain extends HttpServlet { 22 | 23 | /** 24 | * 25 | */ 26 | private static final long serialVersionUID = 1L; 27 | private TrainService trainService = new TrainServiceImpl(); 28 | 29 | /** 30 | * 31 | * @param req 32 | * @param res 33 | * @throws IOException 34 | * @throws ServletException 35 | */ 36 | protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 37 | res.setContentType("text/html"); 38 | PrintWriter pw = res.getWriter(); 39 | TrainUtil.validateUserAuthorization(req, UserRole.ADMIN); 40 | try { 41 | String trainNo = req.getParameter("trainno"); 42 | String message = trainService.deleteTrainById(trainNo); 43 | if (ResponseCode.SUCCESS.toString().equalsIgnoreCase(message)) { 44 | RequestDispatcher rd = req.getRequestDispatcher("CancleTrain.html"); 45 | rd.include(req, res); 46 | pw.println("
Train number " + trainNo 47 | + " has been Deleted Successfully.
"); 48 | } else { 49 | RequestDispatcher rd = req.getRequestDispatcher("CancleTrain.html"); 50 | rd.include(req, res); 51 | pw.println("
Train No." + trainNo + " is Not Available !
"); 52 | } 53 | } catch (Exception e) { 54 | throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); 55 | } 56 | 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/ViewUserProfile.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.RequestDispatcher; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.annotation.WebServlet; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import com.shashi.beans.UserBean; 14 | import com.shashi.constant.UserRole; 15 | import com.shashi.utility.TrainUtil; 16 | 17 | @SuppressWarnings("serial") 18 | @WebServlet("/viewuserprofile") 19 | public class ViewUserProfile extends HttpServlet { 20 | protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 21 | res.setContentType("text/html"); 22 | PrintWriter pw = res.getWriter(); 23 | 24 | TrainUtil.validateUserAuthorization(req, UserRole.CUSTOMER); 25 | 26 | UserBean ub = TrainUtil.getCurrentCustomer(req); 27 | RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); 28 | rd.include(req, res); 29 | pw.println("
" + " " + " Hello " + TrainUtil.getCurrentUserName(req) 30 | + " ! Welcome to our new NITRTC Website" + " " + "
"); 31 | pw.println("
View Profile " 32 | + "Edit Profile " 33 | + "Change Password" + "
"); 34 | pw.println("
Users Profile View
"); 35 | pw.println("
" + "" + "" 36 | + "" 37 | + "" 38 | + "" + "" + "" 40 | + "" + "" + "
Profile Photo :Not Available
User Name :" + ub.getMailId() + "
Password :
First Name :" + ub.getFName() + "
Last Name :" 39 | + ub.getLName() + "
Address :" + ub.getAddr() + "
Phone No:" + ub.getPhNo() + "
Mail Id :" 41 | + ub.getMailId() + "
" + "
"); 42 | 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | TrainBook 4 | TrainBook 5 | 1.0.0-SNAPSHOT 6 | war 7 | 8 | src 9 | 10 | 11 | src 12 | 13 | **/*.java 14 | 15 | 16 | 17 | 18 | 19 | maven-compiler-plugin 20 | 3.8.1 21 | 22 | 1.8 23 | 1.8 24 | 25 | 26 | 27 | maven-war-plugin 28 | 3.2.3 29 | 30 | WebContent 31 | 32 | 33 | 34 | org.apache.maven.plugins 35 | maven-dependency-plugin 36 | 2.3 37 | 38 | 39 | package 40 | 41 | copy 42 | 43 | 44 | 45 | 46 | com.github.jsimone 47 | webapp-runner 48 | 8.0.30.2 49 | webapp-runner.jar 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | org.postgresql 62 | postgresql 63 | 42.3.7 64 | 65 | 66 | 67 | 68 | mysql 69 | mysql-connector-java 70 | 8.0.28 71 | 72 | 73 | 74 | 75 | javax.servlet 76 | javax.servlet-api 77 | 3.1.0 78 | 79 | 80 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/UserViewLinkGet.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.RequestDispatcher; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.annotation.WebServlet; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import com.shashi.beans.TrainBean; 14 | import com.shashi.beans.TrainException; 15 | import com.shashi.constant.UserRole; 16 | import com.shashi.service.TrainService; 17 | import com.shashi.service.impl.TrainServiceImpl; 18 | import com.shashi.utility.TrainUtil; 19 | 20 | @SuppressWarnings("serial") 21 | @WebServlet("/view") 22 | public class UserViewLinkGet extends HttpServlet { 23 | TrainService trainService = new TrainServiceImpl(); 24 | 25 | protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 26 | res.setContentType("text/html"); 27 | PrintWriter pw = res.getWriter(); 28 | TrainUtil.validateUserAuthorization(req, UserRole.CUSTOMER); 29 | try { 30 | String trainNo = req.getParameter("trainNo"); 31 | TrainBean train = trainService.getTrainById(trainNo); 32 | if (train != null) { 33 | RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); 34 | rd.include(req, res); 35 | pw.println("
Selected Train Detail
"); 36 | pw.println("
" + "" + "" + "" + "" + "" + "" + "" + "
Train Name :" 37 | + train.getTr_name() + "
Train Number :" 38 | + train.getTr_no() + "
From Station :" 39 | + train.getFrom_stn() + "
To Station :" 40 | + train.getTo_stn() + "
Available Seats:" 41 | + train.getSeats() + "
Fare (INR) :" 42 | + train.getFare() + " RS
" + "
"); 43 | } else { 44 | RequestDispatcher rd = req.getRequestDispatcher("SearchTrains.html"); 45 | rd.include(req, res); 46 | pw.println("
Train No." + req.getParameter("trainnumber") 47 | + " is Not Available !
"); 48 | } 49 | } catch (Exception e) { 50 | throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); 51 | } 52 | 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/EditUserProfile.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.RequestDispatcher; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.annotation.WebServlet; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import com.shashi.beans.UserBean; 14 | import com.shashi.constant.UserRole; 15 | import com.shashi.utility.TrainUtil; 16 | 17 | @SuppressWarnings("serial") 18 | @WebServlet("/edituserprofile") 19 | public class EditUserProfile extends HttpServlet { 20 | protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 21 | res.setContentType("text/html"); 22 | PrintWriter pw = res.getWriter(); 23 | TrainUtil.validateUserAuthorization(req, UserRole.CUSTOMER); 24 | 25 | UserBean ub = TrainUtil.getCurrentCustomer(req); 26 | RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); 27 | rd.include(req, res); 28 | pw.println("
" + " " + " Hello " + TrainUtil.getCurrentUserName(req) 29 | + " ! Welcome to our new NITRTC Website" + " " + "
"); 30 | pw.println("
View Profile " 31 | + "Edit Profile " 32 | + "Change Password" + "
"); 33 | pw.println("
Profile Update
"); 34 | pw.println("
" + "" 35 | + "" + "" 38 | + "" + "" + "" + "" 42 | + "" 43 | + "
User Name :
First Name :
Last Name :
Address :
Phone No:
" + "
"); 44 | 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/UserSearchTrain.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.RequestDispatcher; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.annotation.WebServlet; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import com.shashi.beans.TrainBean; 14 | import com.shashi.beans.TrainException; 15 | import com.shashi.constant.UserRole; 16 | import com.shashi.service.TrainService; 17 | import com.shashi.service.impl.TrainServiceImpl; 18 | import com.shashi.utility.TrainUtil; 19 | 20 | @SuppressWarnings("serial") 21 | @WebServlet("/searchtrainservlet") 22 | public class UserSearchTrain extends HttpServlet { 23 | private TrainService trainService = new TrainServiceImpl(); 24 | 25 | protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 26 | res.setContentType("text/html"); 27 | PrintWriter pw = res.getWriter(); 28 | 29 | TrainUtil.validateUserAuthorization(req, UserRole.CUSTOMER); 30 | 31 | try { 32 | 33 | String trainNo = req.getParameter("trainnumber"); 34 | TrainBean train = trainService.getTrainById(trainNo); 35 | if (train != null) { 36 | RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); 37 | rd.include(req, res); 38 | pw.println("
Searched Train Detail
"); 39 | pw.println("
" + "" + "" + "" + "" + "" + "" + "" + "
Train Name :" 40 | + train.getTr_name() + "
Train Number :" 41 | + train.getTr_no() + "
From Station :" 42 | + train.getFrom_stn() + "
To Station :" 43 | + train.getTo_stn() + "
Available Seats:" 44 | + train.getSeats() + "
Fare (INR) :" 45 | + train.getFare() + " RS
" + "
"); 46 | } else { 47 | RequestDispatcher rd = req.getRequestDispatcher("SearchTrains.html"); 48 | rd.include(req, res); 49 | pw.println("
Train No." + trainNo + " is Not Available !
"); 50 | } 51 | } catch (Exception e) { 52 | throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); 53 | } 54 | 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/AdminAddTrain.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.RequestDispatcher; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.annotation.WebServlet; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import com.shashi.beans.TrainBean; 14 | import com.shashi.beans.TrainException; 15 | import com.shashi.constant.ResponseCode; 16 | import com.shashi.constant.UserRole; 17 | import com.shashi.service.TrainService; 18 | import com.shashi.service.impl.TrainServiceImpl; 19 | import com.shashi.utility.TrainUtil; 20 | 21 | @WebServlet("/adminaddtrain") 22 | public class AdminAddTrain extends HttpServlet { 23 | 24 | /** 25 | * 26 | */ 27 | private static final long serialVersionUID = 1L; 28 | 29 | private TrainService trainService = new TrainServiceImpl(); 30 | 31 | /** 32 | * 33 | * @param req 34 | * @param res 35 | * @throws IOException 36 | * @throws ServletException 37 | */ 38 | protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 39 | res.setContentType("text/html"); 40 | PrintWriter pw = res.getWriter(); 41 | TrainUtil.validateUserAuthorization(req, UserRole.ADMIN); 42 | try { 43 | TrainBean train = new TrainBean(); 44 | train.setTr_no(Long.parseLong(req.getParameter("trainno"))); 45 | train.setTr_name(req.getParameter("trainname").toUpperCase()); 46 | train.setFrom_stn(req.getParameter("fromstation").toUpperCase()); 47 | train.setTo_stn(req.getParameter("tostation").toUpperCase()); 48 | train.setSeats(Integer.parseInt(req.getParameter("available"))); 49 | train.setFare(Double.parseDouble(req.getParameter("fare"))); 50 | String message = trainService.addTrain(train); 51 | if (ResponseCode.SUCCESS.toString().equalsIgnoreCase(message)) { 52 | RequestDispatcher rd = req.getRequestDispatcher("AddTrains.html"); 53 | rd.include(req, res); 54 | pw.println("
Train Added Successfully!
"); 55 | } else { 56 | RequestDispatcher rd = req.getRequestDispatcher("AddTrains.html"); 57 | rd.include(req, res); 58 | pw.println("
Error in filling the train Detail
"); 59 | } 60 | } catch (Exception e) { 61 | throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); 62 | } 63 | 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /WebContent/UserHome_Css.css: -------------------------------------------------------------------------------- 1 | *{ 2 | box-sizing: border-box; 3 | } 4 | body{ 5 | background-image: url(sandy.jpg); 6 | background-repeat: no-repeat; 7 | margin-left: 10%; 8 | margin-right: 10%; 9 | 10 | } 11 | .hd{ 12 | text-align: center; 13 | padding:10px; 14 | margin-left: 10%; 15 | margin-right: 5%; 16 | color:#cc0066; 17 | font-weight: bold; 18 | font-size:40px; 19 | } 20 | .main{ 21 | border:1px black solid; 22 | background-color: #ffffcc; 23 | border-radius: 10px; 24 | text-align: center; 25 | margin-left:33%; 26 | margin-right: 33.3%; 27 | padding:10px; 28 | margin-bottom: 10px; 29 | color:red; 30 | width:600px; 31 | } 32 | .menu{ 33 | border:1px black solid; 34 | border-radius: 10px; 35 | background-color: white; 36 | color:green; 37 | font-weight: bold; 38 | font-size:14px; 39 | text-align: center; 40 | display:inline-block; 41 | margin:auto; 42 | padding:5px; 43 | margin-top:6px; 44 | } 45 | a:hover{ 46 | color:red; 47 | } 48 | a:link{ 49 | color: green; 50 | text-decoration: none; 51 | } 52 | .tab{ 53 | border:1px black solid; 54 | border-radius: 15px; 55 | background-color: #FFE5CC; 56 | margin-left: 20%; 57 | width:800px; 58 | color:black; 59 | font-weight: bold; 60 | font-style:normal; 61 | text-align:center; 62 | font-size: 15px; 63 | margin-bottom:10px; 64 | padding:10px; 65 | margin-top:10px; 66 | } 67 | 68 | .yel{ 69 | color:yellow; 70 | } 71 | .red{ 72 | color:red; 73 | } 74 | .green{ 75 | color:green; 76 | } 77 | .brown{ 78 | color:brown; 79 | } 80 | .home{ 81 | border:1px black solid; 82 | border-radius: 5px; 83 | background-color:yellow; 84 | margin-left: -10%; 85 | /* width:200px; */ 86 | color:blue; 87 | font-style:italic; 88 | font-weight: bold; 89 | text-align:center; 90 | /* font-size: 22px; */ 91 | margin-bottom:7px; 92 | text-align:center; 93 | height:40px; 94 | padding:auto; 95 | float:left; 96 | clear:both; 97 | width:160px; 98 | 99 | } 100 | table{ 101 | border:2px solid black; 102 | text-align: center; 103 | padding:5px; 104 | width:750px; 105 | } 106 | tr:hover { 107 | background-color: #f5f5f5; 108 | color:black; 109 | } 110 | td{ 111 | padding:5px; 112 | border:1px solid black; 113 | } 114 | th{ 115 | color:blue; 116 | font-size:20px; 117 | } 118 | footer{ 119 | margin-top: 25%; 120 | } -------------------------------------------------------------------------------- /src/com/shashi/servlets/TicketBookingHistory.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | import java.util.List; 6 | 7 | import javax.servlet.RequestDispatcher; 8 | import javax.servlet.ServletException; 9 | import javax.servlet.annotation.WebServlet; 10 | import javax.servlet.http.HttpServlet; 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | 14 | import com.shashi.beans.HistoryBean; 15 | import com.shashi.beans.TrainException; 16 | import com.shashi.constant.UserRole; 17 | import com.shashi.service.BookingService; 18 | import com.shashi.service.impl.BookingServiceImpl; 19 | import com.shashi.utility.TrainUtil; 20 | 21 | @SuppressWarnings("serial") 22 | @WebServlet("/bookingdetails") 23 | public class TicketBookingHistory extends HttpServlet { 24 | 25 | BookingService bookingService = new BookingServiceImpl(); 26 | 27 | protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 28 | res.setContentType("text/html"); 29 | PrintWriter pw = res.getWriter(); 30 | TrainUtil.validateUserAuthorization(req, UserRole.CUSTOMER); 31 | try { 32 | String customerId = TrainUtil.getCurrentUserEmail(req); 33 | List details = bookingService.getAllBookingsByCustomerId(customerId); 34 | if (details != null && !details.isEmpty()) { 35 | RequestDispatcher rd = req.getRequestDispatcher("UserViewTrains.html"); 36 | rd.include(req, res); 37 | pw.println("
Booked Ticket History
"); 38 | pw.println("
" 39 | + ""); 40 | 41 | for (HistoryBean trans : details) { 42 | 43 | pw.println("" + " " + "" + "" + "" + "" + "" 45 | + "" + "" + ""); 47 | } 48 | pw.println("
Transaction IDTrain NumberFrom StationTo StationJourney DateSeatAmount Paid
" + trans.getTransId() + "" + trans.getTr_no() 44 | + "" + trans.getFrom_stn() + "" + trans.getTo_stn() + "" + trans.getDate() + "" + trans.getSeats() + "" 46 | + trans.getAmount() + "
"); 49 | } else { 50 | RequestDispatcher rd = req.getRequestDispatcher("UserViewTrains.html"); 51 | rd.include(req, res); 52 | pw.println("
No any ticket booked, book your first ticket now!!
"); 53 | } 54 | } catch (Exception e) { 55 | throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); 56 | } 57 | 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/AdminSearchTrain.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.RequestDispatcher; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.annotation.WebServlet; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import com.shashi.beans.TrainBean; 14 | import com.shashi.beans.TrainException; 15 | import com.shashi.constant.UserRole; 16 | import com.shashi.service.TrainService; 17 | import com.shashi.service.impl.TrainServiceImpl; 18 | import com.shashi.utility.TrainUtil; 19 | 20 | @SuppressWarnings("serial") 21 | @WebServlet("/adminsearchtrain") 22 | public class AdminSearchTrain extends HttpServlet { 23 | 24 | private TrainService trainService = new TrainServiceImpl(); 25 | 26 | /** 27 | * 28 | * @param req 29 | * @param res 30 | * @throws IOException 31 | * @throws ServletException 32 | */ 33 | protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 34 | res.setContentType("text/html"); 35 | PrintWriter pw = res.getWriter(); 36 | TrainUtil.validateUserAuthorization(req, UserRole.ADMIN); 37 | try { 38 | String trainNo = req.getParameter("trainnumber"); 39 | TrainBean train = trainService.getTrainById(trainNo); 40 | if (train != null) { 41 | RequestDispatcher rd = req.getRequestDispatcher("AdminSearchTrain.html"); 42 | rd.include(req, res); 43 | pw.println("
Searched Train Detail
"); 44 | pw.println("
" + "" + "" + "" + "" + "" + "" + "" + "
Train Name :" 45 | + train.getTr_name() + "
Train Number :" 46 | + train.getTr_no() + "
From Station :" 47 | + train.getFrom_stn() + "
To Station :" 48 | + train.getTo_stn() + "
Available Seats:" 49 | + train.getSeats() + "
Fare (INR) :" 50 | + train.getFare() + " RS
" + "
"); 51 | } else { 52 | RequestDispatcher rd = req.getRequestDispatcher("AdminSearchTrain.html"); 53 | rd.include(req, res); 54 | pw.println("
Train No." + trainNo + " is Not Available !
"); 55 | } 56 | } catch (Exception e) { 57 | throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); 58 | } 59 | 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/AdminViewLinkFwd.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.RequestDispatcher; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.annotation.WebServlet; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import com.shashi.beans.TrainBean; 14 | import com.shashi.beans.TrainException; 15 | import com.shashi.constant.UserRole; 16 | import com.shashi.service.TrainService; 17 | import com.shashi.service.impl.TrainServiceImpl; 18 | import com.shashi.utility.TrainUtil; 19 | 20 | @SuppressWarnings("serial") 21 | @WebServlet("/viewadmin") 22 | public class AdminViewLinkFwd extends HttpServlet { 23 | 24 | TrainService trainService = new TrainServiceImpl(); 25 | 26 | /** 27 | * 28 | * @param req 29 | * @param res 30 | * @throws IOException 31 | * @throws ServletException 32 | */ 33 | protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 34 | res.setContentType("text/html"); 35 | PrintWriter pw = res.getWriter(); 36 | TrainUtil.validateUserAuthorization(req, UserRole.ADMIN); 37 | try { 38 | String trainNo = req.getParameter("trainNo"); 39 | TrainBean train = trainService.getTrainById(trainNo); 40 | if (train != null) { 41 | RequestDispatcher rd = req.getRequestDispatcher("AdminHome.html"); 42 | rd.include(req, res); 43 | pw.println("
Selected Train Detail
"); 44 | pw.println("
" + "" + "" + "" + "" + "" + "" + "" + "
Train Name :" 45 | + train.getTr_name() + "
Train Number :" 46 | + train.getTr_no() + "
From Station :" 47 | + train.getFrom_stn() + "
To Station :" 48 | + train.getTo_stn() + "
Available Seats:" 49 | + train.getSeats() + "
Fare (INR) :" 50 | + train.getFare() + " RS
" + "
"); 51 | } else { 52 | RequestDispatcher rd = req.getRequestDispatcher("AdminSearchTrains.html"); 53 | rd.include(req, res); 54 | pw.println("
Train No." + req.getParameter("trainnumber") 55 | + " is Not Available !
"); 56 | } 57 | } catch (Exception e) { 58 | throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); 59 | 60 | } 61 | 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/BookTrainByRef.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | import java.time.LocalDate; 6 | 7 | import javax.servlet.RequestDispatcher; 8 | import javax.servlet.ServletException; 9 | import javax.servlet.annotation.WebServlet; 10 | import javax.servlet.http.HttpServlet; 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | 14 | import com.shashi.constant.UserRole; 15 | import com.shashi.utility.TrainUtil; 16 | 17 | @SuppressWarnings("serial") 18 | @WebServlet("/booktrainbyref") 19 | public class BookTrainByRef extends HttpServlet { 20 | public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 21 | PrintWriter pw = res.getWriter(); 22 | res.setContentType("text/html"); 23 | TrainUtil.validateUserAuthorization(req, UserRole.CUSTOMER); 24 | 25 | String emailId = TrainUtil.getCurrentUserEmail(req); 26 | long trainNo = Long.parseLong(req.getParameter("trainNo")); 27 | int seat = 1; 28 | String fromStn = req.getParameter("fromStn"); 29 | String toStn = req.getParameter("toStn"); 30 | RequestDispatcher rd = req.getRequestDispatcher("UserViewTrains.html"); 31 | rd.include(req, res); 32 | pw.println("
Your Ticket Booking Information
"); 33 | 34 | pw.println("
" + "
" + "" 35 | + "" + "" 36 | + "" + "" 37 | + "" 39 | + "" 40 | + "" + "" + "
USER ID:" + emailId + "Train NO:" + trainNo + "
From Station:" + fromStn + "To Station :" + toStn + "
Journey Date:" + "" 38 | + "No of Seats:
Select Class" + "" + "Berth Preference" 43 | + "" 44 | + "
" 45 | + "
" + ""); 46 | 47 | } 48 | 49 | } -------------------------------------------------------------------------------- /src/com/shashi/servlets/AdminViewTrainFwd.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | import java.util.List; 6 | 7 | import javax.servlet.RequestDispatcher; 8 | import javax.servlet.ServletException; 9 | import javax.servlet.annotation.WebServlet; 10 | import javax.servlet.http.HttpServlet; 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | 14 | import com.shashi.beans.TrainBean; 15 | import com.shashi.beans.TrainException; 16 | import com.shashi.constant.UserRole; 17 | import com.shashi.service.TrainService; 18 | import com.shashi.service.impl.TrainServiceImpl; 19 | import com.shashi.utility.TrainUtil; 20 | 21 | @SuppressWarnings("serial") 22 | @WebServlet("/adminviewtrainfwd") 23 | public class AdminViewTrainFwd extends HttpServlet { 24 | 25 | private TrainService trainService = new TrainServiceImpl(); 26 | 27 | protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 28 | res.setContentType("text/html"); 29 | PrintWriter pw = res.getWriter(); 30 | TrainUtil.validateUserAuthorization(req, UserRole.ADMIN); 31 | try { 32 | List trains = trainService.getAllTrains(); 33 | if (trains != null && !trains.isEmpty()) { 34 | RequestDispatcher rd = req.getRequestDispatcher("ViewTrains.html"); 35 | rd.include(req, res); 36 | pw.println("
Running Trains
"); 37 | pw.println("
" 38 | + ""); 39 | 40 | for (TrainBean train : trains) { 41 | 42 | pw.println("" + " " + "" + "" + "" + "" 45 | + "" + "" + "" + "" + ""); 48 | } 49 | pw.println("
Train NameTrain NumberFrom StationTo StationSeats AvailableFare (INR)Action
" + train.getTr_name() 44 | + "" + train.getTr_no() + "" + train.getFrom_stn() + "" + train.getTo_stn() + "" + train.getSeats() + "" 46 | + train.getFare() + " RSUpdate
"); 50 | } else { 51 | RequestDispatcher rd = req.getRequestDispatcher("ViewTrains.html"); 52 | rd.include(req, res); 53 | pw.println("
No Running Trains
"); 54 | } 55 | } catch (Exception e) { 56 | throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); 57 | 58 | } 59 | 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/UserAvailServlet.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.RequestDispatcher; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.annotation.WebServlet; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import com.shashi.beans.TrainBean; 14 | import com.shashi.beans.TrainException; 15 | import com.shashi.constant.UserRole; 16 | import com.shashi.service.TrainService; 17 | import com.shashi.service.impl.TrainServiceImpl; 18 | import com.shashi.utility.TrainUtil; 19 | 20 | @SuppressWarnings("serial") 21 | @WebServlet("/useravail") 22 | public class UserAvailServlet extends HttpServlet { 23 | private TrainService trainService = new TrainServiceImpl(); 24 | 25 | protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 26 | res.setContentType("text/html"); 27 | PrintWriter pw = res.getWriter(); 28 | 29 | TrainUtil.validateUserAuthorization(req, UserRole.CUSTOMER); 30 | 31 | try { 32 | 33 | String trainNo = req.getParameter("trainno"); 34 | TrainBean train = trainService.getTrainById(trainNo); 35 | if (train != null) { 36 | RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); 37 | rd.include(req, res); 38 | pw.println( 39 | "
" + " " + " Hello " + TrainUtil.getCurrentUserName(req) 40 | + " ! Welcome to our new NITRTC Website" + " " + "
"); 41 | pw.println("
Available Seats are " 42 | + train.getSeats() + " Seats
"); 43 | pw.println("
" + "" + "" + "" + "" + "" + "" + "" + "
Train Name :" 44 | + train.getTr_name() + "
Train Number :" 45 | + train.getTr_no() + "
From Station :" 46 | + train.getFrom_stn() + "
To Station :" 47 | + train.getTo_stn() + "
Available Seats:" 48 | + train.getSeats() + "
Fare (INR) :" 49 | + train.getFare() + " RS
" + "
"); 50 | } else { 51 | RequestDispatcher rd = req.getRequestDispatcher("Availability.html"); 52 | rd.include(req, res); 53 | 54 | pw.println("
Train No." + trainNo + " is Not Available !
"); 55 | } 56 | } catch (Exception e) { 57 | throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); 58 | } 59 | 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /Dummy-Database.md: -------------------------------------------------------------------------------- 1 | ### Just open the Oracle sql command prompt and login to administrator user and copy paste the following codes for creating dummy database: 2 | 3 | ```SQL 4 | ALTER SESSION SET "_ORACLE_SCRIPT"=TRUE; 5 | 6 | CREATE USER RESERVATION IDENTIFIED BY MANAGER; 7 | 8 | GRANT DBA TO RESERVATION; 9 | 10 | COMMIT; 11 | 12 | CONNECT RESERVATION/MANAGER; 13 | 14 | CREATE TABLE "RESERVATION"."CUSTOMER" 15 | ( 16 | "MAILID" VARCHAR2(40) PRIMARY KEY, 17 | "PWORD" VARCHAR2(20) NOT NULL, 18 | "FNAME" VARCHAR2(20) NOT NULL, 19 | "LNAME" VARCHAR2(20), 20 | "ADDR" VARCHAR2(100), 21 | "PHNO" NUMBER(12) NOT NULL 22 | ); 23 | 24 | CREATE TABLE "RESERVATION"."ADMIN" 25 | ( 26 | "MAILID" VARCHAR2(40) PRIMARY KEY, 27 | "PWORD" VARCHAR2(20) NOT NULL, 28 | "FNAME" VARCHAR2(20) NOT NULL, 29 | "LNAME" VARCHAR2(20), 30 | "ADDR" VARCHAR2(100), 31 | "PHNO" NUMBER(12) NOT NULL 32 | ); 33 | 34 | 35 | CREATE TABLE "RESERVATION"."TRAIN" 36 | ( 37 | "TR_NO" NUMBER(10) PRIMARY KEY, 38 | "TR_NAME" VARCHAR2(70) NOT NULL, 39 | "FROM_STN" VARCHAR2(20) NOT NULL, 40 | "TO_STN" VARCHAR2(20) NOT NULL, 41 | "SEATS" NUMBER(4) NOT NULL, 42 | "FARE" NUMBER(6,2) NOT NULL 43 | ); 44 | 45 | CREATE TABLE "RESERVATION"."HISTORY" 46 | ( 47 | "TRANSID" VARCHAR2(36) PRIMARY KEY, 48 | "MAILID" VARCHAR2(40) REFERENCES "RESERVATION"."CUSTOMER"(MAILID), 49 | "TR_NO" NUMBER(10), 50 | "DATE" DATE, 51 | "FROM_STN" VARCHAR2(20) NOT NULL, 52 | "TO_STN" VARCHAR2(20) NOT NULL, 53 | "SEATS" NUMBER(3) NOT NULL, 54 | "AMOUNT" NUMBER(8,2) NOT NULL 55 | ); 56 | 57 | COMMIT; 58 | 59 | INSERT INTO RESERVATION.ADMIN VALUES('admin@demo.com','admin','System','Admin','Demo Address 123 colony','9874561230'); 60 | INSERT INTO RESERVATION.CUSTOMER VALUES('shashi@demo.com','shashi','Shashi','Raj','Kolkata, West Bengal',954745222); 61 | 62 | INSERT INTO RESERVATION.TRAIN VALUES(10001,'JODHPUR EXP','HOWRAH','JODHPUR', 152, 490.50); 63 | INSERT INTO RESERVATION.TRAIN VALUES(10002,'YAMUNA EXP','GAYA','DELHI', 52, 550.50); 64 | INSERT INTO RESERVATION.TRAIN VALUES(10003,'NILANCHAL EXP','GAYA','HOWRAH', 92, 451); 65 | INSERT INTO RESERVATION.TRAIN VALUES(10004,'JAN SATABDI EXP','RANCHI','PATNA', 182, 550); 66 | INSERT INTO RESERVATION.TRAIN VALUES(10005,'GANGE EXP','MUMBAI','KERALA', 12, 945); 67 | INSERT INTO RESERVATION.TRAIN VALUES(10006,'GARIB RATH EXP','PATNA','DELHI', 1, 1450.75); 68 | INSERT INTO RESERVATION.TRAIN VALUES(10008,'MUMBAI MAIL','HAWRAH','MUMBAI', 100, 2150.75); 69 | INSERT INTO RESERVATION.TRAIN VALUES(10007,'AJMER-SEALDAH EXP','SEALDAH','AJMER', 120, 1000.50); 70 | 71 | INSERT INTO RESERVATION.HISTORY VALUES('BBC374-NSDF-4673','shashi@demo.com',10001,TO_DATE('02-FEB-2024'), 'HOWRAH', 'JODHPUR', 2, 981); 72 | INSERT INTO RESERVATION.HISTORY VALUES('BBC375-NSDF-4675','shashi@demo.com',10004,TO_DATE('12-JAN-2024'), 'RANCHI', 'PATNA', 1, 550); 73 | INSERT INTO RESERVATION.HISTORY VALUES('BBC373-NSDF-4674','shashi@demo.com',10006,TO_DATE('22-JULY-2024'), 'PATNA', 'DELHI', 3, 4352.25); 74 | 75 | COMMIT; 76 | ``` 77 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/AdminTrainUpdate.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.RequestDispatcher; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.annotation.WebServlet; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import com.shashi.beans.TrainBean; 14 | import com.shashi.beans.TrainException; 15 | import com.shashi.service.TrainService; 16 | import com.shashi.service.impl.TrainServiceImpl; 17 | 18 | @SuppressWarnings("serial") 19 | @WebServlet("/adminupdatetrain") 20 | public class AdminTrainUpdate extends HttpServlet { 21 | 22 | private TrainService trainService = new TrainServiceImpl(); 23 | 24 | /** 25 | * 26 | * @param req 27 | * @param res 28 | * @throws IOException 29 | * @throws ServletException 30 | */ 31 | protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 32 | res.setContentType("text/html"); 33 | PrintWriter pw = res.getWriter(); 34 | 35 | try { 36 | String trainNo = req.getParameter("trainnumber"); 37 | TrainBean train = trainService.getTrainById(trainNo); 38 | if (train != null) { 39 | RequestDispatcher rd = req.getRequestDispatcher("AdminHome.html"); 40 | rd.include(req, res); 41 | pw.println("
Train Schedule Update
"); 42 | pw.println("
" + "" 43 | + "" + "" 46 | + "" 48 | + "" 50 | + "" 52 | + "" 54 | + "" 55 | + "
Train No :
Train Name :
From Station :
To Station :
Available seats:
Fare (INR) :
" + "
"); 56 | } else { 57 | RequestDispatcher rd = req.getRequestDispatcher("AdminUpdateTrain.html"); 58 | rd.include(req, res); 59 | pw.println("
Train Not Available
"); 60 | } 61 | } catch (Exception e) { 62 | throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); 63 | 64 | } 65 | 66 | } 67 | 68 | protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 69 | doPost(req, res); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/UserViewTrainFwd.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | import java.util.List; 6 | 7 | import javax.servlet.RequestDispatcher; 8 | import javax.servlet.ServletException; 9 | import javax.servlet.annotation.WebServlet; 10 | import javax.servlet.http.HttpServlet; 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | 14 | import com.shashi.beans.TrainBean; 15 | import com.shashi.beans.TrainException; 16 | import com.shashi.constant.UserRole; 17 | import com.shashi.service.TrainService; 18 | import com.shashi.service.impl.TrainServiceImpl; 19 | import com.shashi.utility.TrainUtil; 20 | 21 | @SuppressWarnings("serial") 22 | @WebServlet("/userviewtrainfwd") 23 | public class UserViewTrainFwd extends HttpServlet { 24 | 25 | TrainService trainService = new TrainServiceImpl(); 26 | 27 | protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 28 | res.setContentType("text/html"); 29 | PrintWriter pw = res.getWriter(); 30 | TrainUtil.validateUserAuthorization(req, UserRole.CUSTOMER); 31 | try { 32 | List trains = trainService.getAllTrains(); 33 | if (trains != null && !trains.isEmpty()) { 34 | RequestDispatcher rd = req.getRequestDispatcher("UserViewTrains.html"); 35 | rd.include(req, res); 36 | pw.println("
Running Trains
"); 37 | pw.println("
" 38 | + ""); 39 | 40 | for (TrainBean train : trains) { 41 | int hr = (int) (Math.random() * 24); 42 | int min = (int) (Math.random() * 60); 43 | String time = (hr < 10 ? ("0" + hr) : hr) + ":" + ((min < 10) ? "0" + min : min); 44 | pw.println("" + " " + "" + "" + "" + "" 47 | + "" + "" + "" + "" + ""); 51 | } 52 | pw.println("
Train NameTrain NumberFrom StationTo StationTimeSeats AvailableFare (INR)Booking
" + train.getTr_name() 46 | + "" + train.getTr_no() + "" + train.getFrom_stn() + "" + train.getTo_stn() + "" + time + "" + train.getSeats() 48 | + "" + train.getFare() + " RS
Book Now
"); 53 | } else { 54 | RequestDispatcher rd = req.getRequestDispatcher("UserViewTrains.html"); 55 | rd.include(req, res); 56 | pw.println("
No Running Trains
"); 57 | } 58 | } catch (Exception e) { 59 | throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); 60 | } 61 | 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/UpdateUserProfile.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.RequestDispatcher; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.annotation.WebServlet; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import com.shashi.beans.TrainException; 14 | import com.shashi.beans.UserBean; 15 | import com.shashi.constant.UserRole; 16 | import com.shashi.service.UserService; 17 | import com.shashi.service.impl.UserServiceImpl; 18 | import com.shashi.utility.TrainUtil; 19 | 20 | @SuppressWarnings("serial") 21 | @WebServlet("/updateuserprofile") 22 | public class UpdateUserProfile extends HttpServlet { 23 | private UserService userService = new UserServiceImpl(UserRole.CUSTOMER); 24 | 25 | protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 26 | res.setContentType("text/html"); 27 | PrintWriter pw = res.getWriter(); 28 | 29 | TrainUtil.validateUserAuthorization(req, UserRole.CUSTOMER); 30 | 31 | UserBean ub = TrainUtil.getCurrentCustomer(req); 32 | 33 | String fName = req.getParameter("firstname"); 34 | String lName = req.getParameter("lastname"); 35 | String addR = req.getParameter("address"); 36 | long phNo = Long.parseLong(req.getParameter("phone")); 37 | String mailId = req.getParameter("mail"); 38 | 39 | ub.setFName(fName); 40 | ub.setLName(lName); 41 | ub.setAddr(addR); 42 | ub.setPhNo(phNo); 43 | ub.setMailId(mailId); 44 | 45 | try { 46 | String message = userService.updateUser(ub); 47 | if ("SUCCESS".equalsIgnoreCase(message)) { 48 | 49 | RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); 50 | rd.include(req, res); 51 | pw.println("
" + " " + " Hello " + ub.getFName() 52 | + " ! Welcome to our new NITRTC Website" + " " + "
"); 53 | pw.println(""); 56 | pw.println("
Your Profile has Been Successfully Updated
"); 57 | } else { 58 | RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); 59 | rd.include(req, res); 60 | pw.println(""); 63 | pw.println("
Please Enter the valid Information
"); 64 | } 65 | } catch (Exception e) { 66 | throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); 67 | 68 | } 69 | 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/com/shashi/service/impl/BookingServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.shashi.service.impl; 2 | 3 | import java.sql.Connection; 4 | import java.sql.PreparedStatement; 5 | import java.sql.ResultSet; 6 | import java.sql.SQLException; 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | import java.util.UUID; 10 | 11 | import com.shashi.beans.HistoryBean; 12 | import com.shashi.beans.TrainException; 13 | import com.shashi.constant.ResponseCode; 14 | import com.shashi.service.BookingService; 15 | import com.shashi.utility.DBUtil; 16 | 17 | //Service Implementaion class for booking details of the ticket 18 | //Creates the booking history and save to database 19 | public class BookingServiceImpl implements BookingService { 20 | 21 | @Override 22 | public List getAllBookingsByCustomerId(String customerEmailId) throws TrainException { 23 | List transactions = null; 24 | String query = "SELECT * FROM HISTORY WHERE MAILID=?"; 25 | try { 26 | Connection con = DBUtil.getConnection(); 27 | PreparedStatement ps = con.prepareStatement(query); 28 | ps.setString(1, customerEmailId); 29 | ResultSet rs = ps.executeQuery(); 30 | transactions = new ArrayList(); 31 | while (rs.next()) { 32 | HistoryBean transaction = new HistoryBean(); 33 | transaction.setTransId(rs.getString("transid")); 34 | transaction.setFrom_stn(rs.getString("from_stn")); 35 | transaction.setTo_stn(rs.getString("to_stn")); 36 | transaction.setDate(rs.getString("date")); 37 | transaction.setMailId(rs.getString("mailid")); 38 | transaction.setSeats(rs.getInt("seats")); 39 | transaction.setAmount(rs.getDouble("amount")); 40 | transaction.setTr_no(rs.getString("tr_no")); 41 | transactions.add(transaction); 42 | } 43 | 44 | ps.close(); 45 | } catch (SQLException e) { 46 | System.out.println(e.getMessage()); 47 | throw new TrainException(e.getMessage()); 48 | } 49 | return transactions; 50 | } 51 | 52 | @Override 53 | public HistoryBean createHistory(HistoryBean details) throws TrainException { 54 | HistoryBean history = null; 55 | String query = "INSERT INTO HISTORY VALUES(?,?,?,?,?,?,?,?)"; 56 | try { 57 | Connection con = DBUtil.getConnection(); 58 | PreparedStatement ps = con.prepareStatement(query); 59 | String transactionId = UUID.randomUUID().toString(); 60 | ps.setString(1, transactionId); 61 | ps.setString(2, details.getMailId()); 62 | ps.setString(3, details.getTr_no()); 63 | ps.setString(4, details.getDate()); 64 | ps.setString(5, details.getFrom_stn()); 65 | ps.setString(6, details.getTo_stn()); 66 | ps.setLong(7, details.getSeats()); 67 | ps.setDouble(8, details.getAmount()); 68 | int response = ps.executeUpdate(); 69 | if (response > 0) { 70 | history = (HistoryBean) details; 71 | history.setTransId(transactionId); 72 | } else { 73 | throw new TrainException(ResponseCode.INTERNAL_SERVER_ERROR); 74 | } 75 | ps.close(); 76 | } catch (SQLException e) { 77 | System.out.println(e.getMessage()); 78 | throw new TrainException(e.getMessage()); 79 | } 80 | return history; 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/FareEnq.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | import java.util.List; 6 | 7 | import javax.servlet.RequestDispatcher; 8 | import javax.servlet.ServletException; 9 | import javax.servlet.annotation.WebServlet; 10 | import javax.servlet.http.HttpServlet; 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | 14 | import com.shashi.beans.TrainBean; 15 | import com.shashi.beans.TrainException; 16 | import com.shashi.constant.UserRole; 17 | import com.shashi.service.TrainService; 18 | import com.shashi.service.impl.TrainServiceImpl; 19 | import com.shashi.utility.TrainUtil; 20 | 21 | @SuppressWarnings("serial") 22 | @WebServlet("/fareenq") 23 | public class FareEnq extends HttpServlet { 24 | TrainService trainService = new TrainServiceImpl(); 25 | 26 | protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 27 | res.setContentType("text/html"); 28 | PrintWriter pw = res.getWriter(); 29 | 30 | TrainUtil.validateUserAuthorization(req, UserRole.CUSTOMER); 31 | 32 | try { 33 | String fromStation = req.getParameter("fromstation"); 34 | String toStation = req.getParameter("tostation"); 35 | List trains = trainService.getTrainsBetweenStations(fromStation, toStation); 36 | if (trains != null && !trains.isEmpty()) { 37 | RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); 38 | rd.include(req, res); 39 | pw.println("
Fare for Trains BetWeen Station " + fromStation + " and " 40 | + toStation + " is as below
"); 41 | pw.println("
" 42 | + ""); 43 | for (TrainBean train : trains) { 44 | int hr = (int) (Math.random() * 24); 45 | int min = (int) (Math.random() * 60); 46 | String time = (hr < 10 ? ("0" + hr) : hr) + ":" + ((min < 10) ? "0" + min : min); 47 | 48 | pw.println("" + "" + "" 49 | + "" + "" + "" + "" + "" + ""); 54 | } 55 | pw.println("
Train NameTrain NoFrom StnTo StnTimeSeatsFare (INR)Action
" + train.getTr_name() + "" + train.getTr_no() + "" + train.getFrom_stn() + "" + train.getTo_stn() + "" 50 | + time + "" + train.getSeats() + "" + train.getFare() 51 | + " RS
Book Now
"); 56 | } else { 57 | RequestDispatcher rd = req.getRequestDispatcher("TrainBwStn.html"); 58 | rd.include(req, res); 59 | pw.println("
There are no trains Between " + fromStation + " and " 60 | + toStation + "
"); 61 | } 62 | } catch (Exception e) { 63 | throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); 64 | } 65 | 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/ErrorHandlerServlet.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | import java.util.Optional; 6 | 7 | import javax.servlet.RequestDispatcher; 8 | import javax.servlet.ServletException; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import com.shashi.beans.TrainException; 14 | import com.shashi.constant.ResponseCode; 15 | 16 | public class ErrorHandlerServlet extends HttpServlet { 17 | 18 | /** 19 | * 20 | */ 21 | private static final long serialVersionUID = 1L; 22 | 23 | public void service(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 24 | PrintWriter pw = res.getWriter(); 25 | res.setContentType("text/html"); 26 | 27 | // Fetch the exceptions 28 | Throwable throwable = (Throwable) req.getAttribute("javax.servlet.error.exception"); 29 | Integer statusCode = (Integer) req.getAttribute("javax.servlet.error.status_code"); 30 | String servletName = (String) req.getAttribute("javax.servlet.error.servlet_name"); 31 | String requestUri = (String) req.getAttribute("javax.servlet.error.request_uri"); 32 | String errorMessage = ResponseCode.INTERNAL_SERVER_ERROR.getMessage(); 33 | String errorCode = ResponseCode.INTERNAL_SERVER_ERROR.name(); 34 | 35 | if (statusCode == null) 36 | statusCode = 0; 37 | Optional errorCodes = ResponseCode.getMessageByStatusCode(statusCode); 38 | if (errorCodes.isPresent()) { 39 | errorMessage = errorCodes.get().getMessage(); 40 | errorCode = errorCodes.get().name(); 41 | } 42 | 43 | if (throwable != null && throwable instanceof TrainException) { 44 | TrainException trainException = (TrainException) throwable; 45 | if (trainException != null) { 46 | errorMessage = trainException.getMessage(); 47 | statusCode = trainException.getStatusCode(); 48 | errorCode = trainException.getErrorCode(); 49 | trainException.printStackTrace(); 50 | } 51 | } else if (throwable != null) { 52 | errorMessage = throwable.getMessage(); 53 | errorCode = throwable.getLocalizedMessage(); 54 | } 55 | 56 | System.out.println("======ERROR TRIGGERED========"); 57 | System.out.println("Servlet Name: " + servletName); 58 | System.out.println("Request URI: " + requestUri); 59 | System.out.println("Status Code: " + statusCode); 60 | System.out.println("Error Code: " + errorCode); 61 | System.out.println("Error Message: " + errorMessage); 62 | System.out.println("============================="); 63 | 64 | if (statusCode == 401) { 65 | RequestDispatcher rd = req.getRequestDispatcher("UserLogin.html"); 66 | rd.include(req, res); 67 | pw.println("
" + errorMessage + "
"); 68 | 69 | } else { 70 | RequestDispatcher rd = req.getRequestDispatcher("error.html"); 71 | rd.include(req, res); 72 | pw.println("
\r\n" 73 | + "

" + errorCode + "


\r\n" + "

" 74 | + errorMessage + "

\r\n" + "
"); 75 | 76 | } 77 | 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/TrainBwStn.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | import java.util.List; 6 | 7 | import javax.servlet.RequestDispatcher; 8 | import javax.servlet.ServletException; 9 | import javax.servlet.annotation.WebServlet; 10 | import javax.servlet.http.HttpServlet; 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | 14 | import com.shashi.beans.TrainBean; 15 | import com.shashi.beans.TrainException; 16 | import com.shashi.constant.UserRole; 17 | import com.shashi.service.TrainService; 18 | import com.shashi.service.impl.TrainServiceImpl; 19 | import com.shashi.utility.TrainUtil; 20 | 21 | @SuppressWarnings("serial") 22 | @WebServlet("/trainbwstn") 23 | public class TrainBwStn extends HttpServlet { 24 | private TrainService trainService = new TrainServiceImpl(); 25 | 26 | protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 27 | res.setContentType("text/html"); 28 | PrintWriter pw = res.getWriter(); 29 | TrainUtil.validateUserAuthorization(req, UserRole.CUSTOMER); 30 | try { 31 | String fromStation = req.getParameter("fromstation"); 32 | String toStation = req.getParameter("tostation"); 33 | List trains = trainService.getTrainsBetweenStations(fromStation, toStation); 34 | if (trains != null && !trains.isEmpty()) { 35 | RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); 36 | rd.include(req, res); 37 | pw.println("
Trains BetWeen Station " 38 | + req.getParameter("fromstation") + " and " + req.getParameter("tostation") + "
"); 39 | pw.println("
" 40 | + ""); 41 | for (TrainBean train : trains) { 42 | int hr = (int) (Math.random() * 24); 43 | int min = (int) (Math.random() * 60); 44 | String time = (hr < 10 ? ("0" + hr) : hr) + ":" + ((min < 10) ? "0" + min : min); 45 | 46 | pw.println("" + "" + "" 47 | + "" + "" + "" + "" + "" + ""); 52 | } 53 | pw.println("
Train NameTrain NoFrom StnTo StnTimeSeatsFare (INR)Action
" + train.getTr_name() + "" + train.getTr_no() + "" + train.getFrom_stn() + "" + train.getTo_stn() + "" 48 | + time + "" + train.getSeats() + "" + train.getFare() 49 | + " RS
Book Now
"); 54 | } else { 55 | RequestDispatcher rd = req.getRequestDispatcher("TrainBwStn.html"); 56 | rd.include(req, res); 57 | pw.println("
There are no trains Between " 58 | + req.getParameter("fromstation") + " and " + req.getParameter("tostation") + "
"); 59 | } 60 | } catch (Exception e) { 61 | throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); 62 | } 63 | 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/com/shashi/utility/TrainUtil.java: -------------------------------------------------------------------------------- 1 | package com.shashi.utility; 2 | 3 | import java.util.Arrays; 4 | import java.util.Optional; 5 | import java.util.UUID; 6 | 7 | import javax.servlet.http.Cookie; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | 11 | import com.shashi.beans.TrainException; 12 | import com.shashi.beans.UserBean; 13 | import com.shashi.constant.ResponseCode; 14 | import com.shashi.constant.UserRole; 15 | import com.shashi.service.UserService; 16 | import com.shashi.service.impl.UserServiceImpl; 17 | 18 | public class TrainUtil { 19 | 20 | public static Optional readCookie(HttpServletRequest request, String key) { 21 | Cookie[] cookies = request.getCookies(); 22 | if (cookies == null) { 23 | return Optional.empty(); 24 | } 25 | return Arrays.stream(cookies).filter(c -> key.equals(c.getName())).map(Cookie::getValue).findAny(); 26 | } 27 | 28 | public static String login(HttpServletRequest request, HttpServletResponse response, UserRole userRole, 29 | String username, String password) { 30 | UserService userService = new UserServiceImpl(userRole); 31 | String responseCode = ResponseCode.UNAUTHORIZED.toString(); 32 | try { 33 | UserBean user = userService.loginUser(username, password); 34 | 35 | // Add the user details to the ServletContext with key as role name 36 | request.getServletContext().setAttribute(userRole.toString(), user); 37 | 38 | // Store the user firstName and mailId in the http session 39 | request.getSession().setAttribute("uName", user.getFName()); 40 | request.getSession().setAttribute("mailid", user.getMailId()); 41 | 42 | // Add the sessionId to the cookie with key as sessionId 43 | Cookie cookie = new Cookie("sessionIdFor" + userRole.toString(), UUID.randomUUID().toString()); 44 | 45 | // set the max age for the cookie 46 | cookie.setMaxAge(600); // Expires after 10 MIN 47 | 48 | // add the cookie to the response 49 | response.addCookie(cookie); 50 | 51 | // set the responseCode to success 52 | responseCode = ResponseCode.SUCCESS.toString(); 53 | 54 | } catch (TrainException e) { 55 | responseCode += " : " + e.getMessage(); 56 | } 57 | 58 | return responseCode; 59 | } 60 | 61 | public static boolean isLoggedIn(HttpServletRequest request, UserRole userRole) { 62 | Optional sessionId = readCookie(request, "sessionIdFor" + userRole.toString()); 63 | return sessionId != null && sessionId.isPresent(); 64 | } 65 | 66 | public static void validateUserAuthorization(HttpServletRequest request, UserRole userRole) throws TrainException { 67 | if (!isLoggedIn(request, userRole)) { 68 | throw new TrainException(ResponseCode.SESSION_EXPIRED); 69 | } 70 | } 71 | 72 | public static boolean logout(HttpServletResponse response) { 73 | 74 | // Set the max age to 0 for the admin and customer cookies 75 | Cookie cookie = new Cookie("sessionIdFor" + UserRole.ADMIN.toString(), UUID.randomUUID().toString()); 76 | cookie.setMaxAge(0); 77 | 78 | Cookie cookie2 = new Cookie("sessionIdFor" + UserRole.CUSTOMER.toString(), UUID.randomUUID().toString()); 79 | cookie2.setMaxAge(0); 80 | 81 | response.addCookie(cookie); 82 | response.addCookie(cookie2); 83 | 84 | return true; 85 | } 86 | 87 | public static String getCurrentUserName(HttpServletRequest req) { 88 | return (String) req.getSession().getAttribute("uName"); 89 | } 90 | 91 | public static String getCurrentUserEmail(HttpServletRequest req) { 92 | return (String) req.getSession().getAttribute("mailid"); 93 | } 94 | 95 | public static UserBean getCurrentCustomer(HttpServletRequest req) { 96 | return (UserBean) req.getServletContext().getAttribute(UserRole.CUSTOMER.toString()); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/ChangeUserPwd.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.RequestDispatcher; 7 | //import javax.servlet.ServletContext; 8 | import javax.servlet.ServletException; 9 | import javax.servlet.annotation.WebServlet; 10 | import javax.servlet.http.HttpServlet; 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | 14 | import com.shashi.beans.TrainException; 15 | import com.shashi.beans.UserBean; 16 | import com.shashi.constant.UserRole; 17 | import com.shashi.service.UserService; 18 | import com.shashi.service.impl.UserServiceImpl; 19 | import com.shashi.utility.TrainUtil; 20 | 21 | @SuppressWarnings("serial") 22 | @WebServlet("/changeuserpwd") 23 | public class ChangeUserPwd extends HttpServlet { 24 | private UserService userService = new UserServiceImpl(UserRole.CUSTOMER); 25 | 26 | protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 27 | res.setContentType("text/html"); 28 | PrintWriter pw = res.getWriter(); 29 | UserBean currentUser = TrainUtil.getCurrentCustomer(req); 30 | 31 | try { 32 | String u_Name = req.getParameter("username"); 33 | String oldPWord = (String) req.getParameter("oldpassword"); 34 | String newPWord = req.getParameter("newpassword"); 35 | if (currentUser.getMailId().equals(u_Name)) { 36 | if (currentUser.getPWord().equals(oldPWord)) { 37 | currentUser.setPWord(newPWord); 38 | String message = userService.updateUser(currentUser); 39 | if ("SUCCESS".equalsIgnoreCase(message)) { 40 | RequestDispatcher rd = req.getRequestDispatcher("UserLogin.html"); 41 | rd.include(req, res); 42 | TrainUtil.logout(res); 43 | pw.println( 44 | "
Your Username and Password has Been Updated Successfully
Please Login Again !
"); 45 | } else { 46 | RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); 47 | rd.include(req, res); 48 | pw.println("
" + " " + " Hello " + currentUser.getFName() 49 | + " ! Welcome to our new NITRTC Website" + " " + "
"); 50 | pw.println("
View Profile " 51 | + "Edit Profile " 52 | + "Change Password" + "
"); 53 | pw.println("
Invalid Username and Old Password !
"); 54 | } 55 | } else { 56 | RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); 57 | rd.include(req, res); 58 | pw.println(""); 61 | pw.println("
Wrong Old PassWord!
"); 62 | } 63 | } else { 64 | RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); 65 | rd.include(req, res); 66 | pw.println(""); 69 | pw.println("
Invalid UserName
"); 70 | } 71 | 72 | } catch (Exception e) { 73 | throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); 74 | } 75 | 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /WebContent/Payment.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Payments 6 | 8 | 25 | 26 | 27 | 28 | 29 |
30 |

Card Payment Gateway

31 |
32 |
33 |
34 | 37 |
38 |
39 | 42 |
43 |
44 | 47 |
48 |
49 | 52 |
53 |
54 | 57 |
58 |
59 | 62 |
63 |
64 | 67 |
68 |
69 | 72 |
73 |
74 | 77 |
78 |
79 | 80 | 81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 | 90 | 92 | 94 | 96 |
97 |
98 |
99 |
100 |
101 | 102 |
103 |
104 |
105 | 106 |
107 | 111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 | 121 |
122 |
123 |
124 |
125 | 127 |
128 |
129 |
130 |
131 |
132 |
133 | 135 |
136 |
137 |
138 |
139 | 147 |
148 | 149 |
150 |
151 |
152 |
153 | 154 | 155 | 156 | 157 | 158 | 160 | 161 | 162 | 164 | -------------------------------------------------------------------------------- /src/com/shashi/servlets/BookTrains.java: -------------------------------------------------------------------------------- 1 | package com.shashi.servlets; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | import java.text.SimpleDateFormat; 6 | import java.time.LocalDate; 7 | 8 | import javax.servlet.RequestDispatcher; 9 | import javax.servlet.ServletContext; 10 | import javax.servlet.ServletException; 11 | import javax.servlet.annotation.WebServlet; 12 | import javax.servlet.http.HttpServlet; 13 | import javax.servlet.http.HttpServletRequest; 14 | import javax.servlet.http.HttpServletResponse; 15 | 16 | import com.shashi.beans.HistoryBean; 17 | import com.shashi.beans.TrainBean; 18 | import com.shashi.beans.TrainException; 19 | import com.shashi.constant.ResponseCode; 20 | import com.shashi.constant.UserRole; 21 | import com.shashi.service.BookingService; 22 | import com.shashi.service.TrainService; 23 | import com.shashi.service.impl.BookingServiceImpl; 24 | import com.shashi.service.impl.TrainServiceImpl; 25 | import com.shashi.utility.TrainUtil; 26 | 27 | @SuppressWarnings("serial") 28 | @WebServlet("/booktrains") 29 | public class BookTrains extends HttpServlet { 30 | 31 | private TrainService trainService = new TrainServiceImpl(); 32 | private BookingService bookingService = new BookingServiceImpl(); 33 | 34 | public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 35 | PrintWriter pw = res.getWriter(); 36 | res.setContentType("text/html"); 37 | TrainUtil.validateUserAuthorization(req, UserRole.CUSTOMER); 38 | 39 | RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); 40 | rd.include(req, res); 41 | 42 | ServletContext sct = req.getServletContext(); 43 | 44 | try { 45 | int seat = (int) sct.getAttribute("seats"); 46 | String trainNo = (String) sct.getAttribute("trainnumber"); 47 | String journeyDate = (String) sct.getAttribute("journeydate"); 48 | String seatClass = (String) sct.getAttribute("class"); 49 | 50 | String userMailId = TrainUtil.getCurrentUserEmail(req); 51 | 52 | SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd"); 53 | SimpleDateFormat outputFormat = new SimpleDateFormat("dd-MMM-yyyy"); 54 | java.util.Date utilDate; 55 | String date = LocalDate.now().toString(); 56 | utilDate = inputFormat.parse(journeyDate); 57 | date = outputFormat.format(utilDate); 58 | 59 | TrainBean train = trainService.getTrainById(trainNo); 60 | 61 | if (train != null) { 62 | int avail = train.getSeats(); 63 | if (seat > avail) { 64 | pw.println("
Only " + avail 65 | + " Seats are Available in this Train!
"); 66 | 67 | } else if (seat <= avail) { 68 | avail = avail - seat; 69 | train.setSeats(avail); 70 | String responseCode = trainService.updateTrain(train); 71 | if (ResponseCode.SUCCESS.toString().equalsIgnoreCase(responseCode)) { 72 | 73 | HistoryBean bookingDetails = new HistoryBean(); 74 | Double totalAmount = train.getFare() * seat; 75 | bookingDetails.setAmount(totalAmount); 76 | bookingDetails.setFrom_stn(train.getFrom_stn()); 77 | bookingDetails.setTo_stn(train.getTo_stn()); 78 | bookingDetails.setTr_no(trainNo); 79 | bookingDetails.setSeats(seat); 80 | bookingDetails.setMailId(userMailId); 81 | bookingDetails.setDate(date); 82 | 83 | HistoryBean transaction = bookingService.createHistory(bookingDetails); 84 | pw.println("
" + "
"); 87 | pw.println("
" + "
"); 98 | 99 | } else { 100 | pw.println( 101 | "
Transaction Declined. Try Again !
"); 102 | 103 | } 104 | } 105 | } else { 106 | pw.println("
Invalid Train Number !
"); 107 | 108 | } 109 | 110 | } catch (Exception e) { 111 | throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); 112 | } 113 | 114 | sct.removeAttribute("seat"); 115 | sct.removeAttribute("trainNo"); 116 | sct.removeAttribute("journeyDate"); 117 | sct.removeAttribute("class"); 118 | } 119 | 120 | } 121 | -------------------------------------------------------------------------------- /src/com/shashi/service/impl/TrainServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.shashi.service.impl; 2 | 3 | import java.sql.Connection; 4 | import java.sql.PreparedStatement; 5 | import java.sql.ResultSet; 6 | import java.sql.SQLException; 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | import com.shashi.beans.TrainBean; 11 | import com.shashi.beans.TrainException; 12 | import com.shashi.constant.ResponseCode; 13 | import com.shashi.service.TrainService; 14 | import com.shashi.utility.DBUtil; 15 | 16 | public class TrainServiceImpl implements TrainService { 17 | 18 | @Override 19 | public String addTrain(TrainBean train) { 20 | String responseCode = ResponseCode.FAILURE.toString(); 21 | String query = "INSERT INTO TRAIN VALUES(?,?,?,?,?,?)"; 22 | try { 23 | Connection con = DBUtil.getConnection(); 24 | PreparedStatement ps = con.prepareStatement(query); 25 | ps.setLong(1, train.getTr_no()); 26 | ps.setString(2, train.getTr_name()); 27 | ps.setString(3, train.getFrom_stn()); 28 | ps.setString(4, train.getTo_stn()); 29 | ps.setLong(5, train.getSeats()); 30 | ps.setDouble(6, train.getFare()); 31 | ResultSet rs = ps.executeQuery(); 32 | if (rs.next()) { 33 | responseCode = ResponseCode.SUCCESS.toString(); 34 | } 35 | ps.close(); 36 | } catch (SQLException | TrainException e) { 37 | responseCode += " : " + e.getMessage(); 38 | } 39 | return responseCode; 40 | } 41 | 42 | @Override 43 | public String deleteTrainById(String trainNo) { 44 | String responseCode = ResponseCode.FAILURE.toString(); 45 | String query = "DELETE FROM TRAIN WHERE TR_NO=?"; 46 | try { 47 | Connection con = DBUtil.getConnection(); 48 | PreparedStatement ps = con.prepareStatement(query); 49 | ps.setString(1, trainNo); 50 | int response = ps.executeUpdate(); 51 | if (response > 0) { 52 | responseCode = ResponseCode.SUCCESS.toString(); 53 | } 54 | ps.close(); 55 | } catch (SQLException | TrainException e) { 56 | responseCode += " : " + e.getMessage(); 57 | } 58 | return responseCode; 59 | } 60 | 61 | @Override 62 | public String updateTrain(TrainBean train) { 63 | String responseCode = ResponseCode.FAILURE.toString(); 64 | String query = "UPDATE TRAIN SET TR_NAME=?, FROM_STN=?,TO_STN=?,SEATS=?,FARE=? WHERE TR_NO=?"; 65 | try { 66 | Connection con = DBUtil.getConnection(); 67 | PreparedStatement ps = con.prepareStatement(query); 68 | ps.setString(1, train.getTr_name()); 69 | ps.setString(2, train.getFrom_stn()); 70 | ps.setString(3, train.getTo_stn()); 71 | ps.setLong(4, train.getSeats()); 72 | ps.setDouble(5, train.getFare()); 73 | ps.setDouble(6, train.getTr_no()); 74 | ResultSet rs = ps.executeQuery(); 75 | if (rs.next()) { 76 | responseCode = ResponseCode.SUCCESS.toString(); 77 | } 78 | ps.close(); 79 | } catch (SQLException | TrainException e) { 80 | responseCode += " : " + e.getMessage(); 81 | } 82 | return responseCode; 83 | } 84 | 85 | @Override 86 | public TrainBean getTrainById(String trainNo) throws TrainException { 87 | TrainBean train = null; 88 | String query = "SELECT * FROM TRAIN WHERE TR_NO=?"; 89 | try { 90 | Connection con = DBUtil.getConnection(); 91 | PreparedStatement ps = con.prepareStatement(query); 92 | ps.setString(1, trainNo); 93 | ResultSet rs = ps.executeQuery(); 94 | if (rs.next()) { 95 | train = new TrainBean(); 96 | train.setFare(rs.getDouble("fare")); 97 | train.setFrom_stn(rs.getString("from_stn")); 98 | train.setTo_stn(rs.getString("to_stn")); 99 | train.setTr_name(rs.getString("tr_name")); 100 | train.setTr_no(rs.getLong("tr_no")); 101 | train.setSeats(rs.getInt("seats")); 102 | } 103 | ps.close(); 104 | } catch (SQLException e) { 105 | System.out.println(e.getMessage()); 106 | throw new TrainException(e.getMessage()); 107 | } 108 | return train; 109 | } 110 | 111 | @Override 112 | public List getAllTrains() throws TrainException { 113 | List trains = null; 114 | String query = "SELECT * FROM TRAIN"; 115 | try { 116 | Connection con = DBUtil.getConnection(); 117 | PreparedStatement ps = con.prepareStatement(query); 118 | ResultSet rs = ps.executeQuery(); 119 | trains = new ArrayList(); 120 | while (rs.next()) { 121 | TrainBean train = new TrainBean(); 122 | train.setFare(rs.getDouble("fare")); 123 | train.setFrom_stn(rs.getString("from_stn")); 124 | train.setTo_stn(rs.getString("to_stn")); 125 | train.setTr_name(rs.getString("tr_name")); 126 | train.setTr_no(rs.getLong("tr_no")); 127 | train.setSeats(rs.getInt("seats")); 128 | trains.add(train); 129 | } 130 | 131 | ps.close(); 132 | } catch (SQLException e) { 133 | System.out.println(e.getMessage()); 134 | throw new TrainException(e.getMessage()); 135 | } 136 | return trains; 137 | } 138 | 139 | @Override 140 | public List getTrainsBetweenStations(String fromStation, String toStation) throws TrainException { 141 | List trains = null; 142 | String query = "SELECT * FROM TRAIN WHERE UPPER(FROM_STN) LIKE UPPER(?) AND UPPER(TO_STN) LIKE UPPER(?)"; 143 | 144 | try { 145 | Connection con = DBUtil.getConnection(); 146 | PreparedStatement ps = con.prepareStatement(query); 147 | ps.setString(1, "%" + fromStation + "%"); 148 | ps.setString(2, "%" + toStation + "%"); 149 | ResultSet rs = ps.executeQuery(); 150 | trains = new ArrayList(); 151 | while (rs.next()) { 152 | TrainBean train = new TrainBean(); 153 | train.setFare(rs.getDouble("fare")); 154 | train.setFrom_stn(rs.getString("from_stn")); 155 | train.setTo_stn(rs.getString("to_stn")); 156 | train.setTr_name(rs.getString("tr_name")); 157 | train.setTr_no(rs.getLong("tr_no")); 158 | train.setSeats(rs.getInt("seats")); 159 | trains.add(train); 160 | } 161 | 162 | ps.close(); 163 | } catch (SQLException e) { 164 | System.out.println(e.getMessage()); 165 | throw new TrainException(e.getMessage()); 166 | } 167 | return trains; 168 | } 169 | 170 | } 171 | -------------------------------------------------------------------------------- /src/com/shashi/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.shashi.service.impl; 2 | 3 | import java.sql.Connection; 4 | import java.sql.PreparedStatement; 5 | import java.sql.ResultSet; 6 | import java.sql.SQLException; 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | import com.shashi.beans.TrainException; 11 | import com.shashi.beans.UserBean; 12 | import com.shashi.constant.ResponseCode; 13 | import com.shashi.constant.UserRole; 14 | import com.shashi.service.UserService; 15 | import com.shashi.utility.DBUtil; 16 | 17 | public class UserServiceImpl implements UserService { 18 | 19 | private final String TABLE_NAME; 20 | 21 | public UserServiceImpl(UserRole userRole) { 22 | if (userRole == null) { 23 | userRole = UserRole.CUSTOMER; 24 | } 25 | this.TABLE_NAME = userRole.toString(); 26 | } 27 | 28 | @Override 29 | public UserBean getUserByEmailId(String customerEmailId) throws TrainException { 30 | UserBean customer = null; 31 | String query = "SELECT * FROM " + TABLE_NAME + " WHERE MAILID=?"; 32 | try { 33 | Connection con = DBUtil.getConnection(); 34 | PreparedStatement ps = con.prepareStatement(query); 35 | ps.setString(1, customerEmailId); 36 | ResultSet rs = ps.executeQuery(); 37 | if (rs.next()) { 38 | customer = new UserBean(); 39 | customer.setFName(rs.getString("fname")); 40 | customer.setLName(rs.getString("lname")); 41 | customer.setAddr(rs.getString("addr")); 42 | customer.setMailId(rs.getString("mailid")); 43 | customer.setPhNo(rs.getLong("phno")); 44 | } else { 45 | throw new TrainException(ResponseCode.NO_CONTENT); 46 | } 47 | ps.close(); 48 | } catch (SQLException e) { 49 | System.out.println(e.getMessage()); 50 | throw new TrainException(e.getMessage()); 51 | } 52 | return customer; 53 | } 54 | 55 | @Override 56 | public List getAllUsers() throws TrainException { 57 | List customers = null; 58 | String query = "SELECT * FROM " + TABLE_NAME; 59 | try { 60 | Connection con = DBUtil.getConnection(); 61 | PreparedStatement ps = con.prepareStatement(query); 62 | ResultSet rs = ps.executeQuery(); 63 | customers = new ArrayList(); 64 | while (rs.next()) { 65 | UserBean customer = new UserBean(); 66 | customer.setFName(rs.getString("fname")); 67 | customer.setLName(rs.getString("lname")); 68 | customer.setAddr(rs.getString("addr")); 69 | customer.setMailId(rs.getString("mailid")); 70 | customer.setPhNo(rs.getLong("phno")); 71 | customers.add(customer); 72 | } 73 | 74 | if (customers.isEmpty()) { 75 | throw new TrainException(ResponseCode.NO_CONTENT); 76 | } 77 | ps.close(); 78 | } catch (SQLException e) { 79 | System.out.println(e.getMessage()); 80 | throw new TrainException(e.getMessage()); 81 | } 82 | return customers; 83 | } 84 | 85 | @Override 86 | public String updateUser(UserBean customer) { 87 | String responseCode = ResponseCode.FAILURE.toString(); 88 | String query = "UPDATE " + TABLE_NAME + " SET FNAME=?,LNAME=?,ADDR=?,PHNO=? WHERE MAILID=?"; 89 | try { 90 | Connection con = DBUtil.getConnection(); 91 | PreparedStatement ps = con.prepareStatement(query); 92 | ps.setString(1, customer.getFName()); 93 | ps.setString(2, customer.getLName()); 94 | ps.setString(3, customer.getAddr()); 95 | ps.setLong(4, customer.getPhNo()); 96 | ps.setString(5, customer.getMailId()); 97 | int response = ps.executeUpdate(); 98 | if (response > 0) { 99 | responseCode = ResponseCode.SUCCESS.toString(); 100 | } 101 | ps.close(); 102 | } catch (SQLException | TrainException e) { 103 | responseCode += " : " + e.getMessage(); 104 | } 105 | return responseCode; 106 | } 107 | 108 | @Override 109 | public String deleteUser(UserBean customer) { 110 | String responseCode = ResponseCode.FAILURE.toString(); 111 | String query = "DELETE FROM " + TABLE_NAME + " WHERE MAILID=?"; 112 | try { 113 | Connection con = DBUtil.getConnection(); 114 | PreparedStatement ps = con.prepareStatement(query); 115 | ps.setString(1, customer.getMailId()); 116 | 117 | int response = ps.executeUpdate(); 118 | if (response > 0) { 119 | responseCode = ResponseCode.SUCCESS.toString(); 120 | } 121 | ps.close(); 122 | } catch (SQLException | TrainException e) { 123 | responseCode += " : " + e.getMessage(); 124 | } 125 | return responseCode; 126 | } 127 | 128 | @Override 129 | public String registerUser(UserBean customer) { 130 | String responseCode = ResponseCode.FAILURE.toString(); 131 | String query = "INSERT INTO " + TABLE_NAME + " VALUES(?,?,?,?,?,?)"; 132 | try { 133 | Connection con = DBUtil.getConnection(); 134 | PreparedStatement ps = con.prepareStatement(query); 135 | ps.setString(1, customer.getMailId()); 136 | ps.setString(2, customer.getPWord()); 137 | ps.setString(3, customer.getFName()); 138 | ps.setString(4, customer.getLName()); 139 | ps.setString(5, customer.getAddr()); 140 | ps.setLong(6, customer.getPhNo()); 141 | ResultSet rs = ps.executeQuery(); 142 | if (rs.next()) { 143 | responseCode = ResponseCode.SUCCESS.toString(); 144 | } 145 | ps.close(); 146 | } catch (SQLException | TrainException e) { 147 | if (e.getMessage().toUpperCase().contains("ORA-00001")) { 148 | responseCode += " : " + "User With Id: " + customer.getMailId() + " is already registered "; 149 | } else { 150 | responseCode += " : " + e.getMessage(); 151 | } 152 | } 153 | return responseCode; 154 | } 155 | 156 | @Override 157 | public UserBean loginUser(String username, String password) throws TrainException { 158 | UserBean customer = null; 159 | String query = "SELECT * FROM " + TABLE_NAME + " WHERE MAILID=? AND PWORD=?"; 160 | try { 161 | Connection con = DBUtil.getConnection(); 162 | PreparedStatement ps = con.prepareStatement(query); 163 | ps.setString(1, username); 164 | ps.setString(2, password); 165 | ResultSet rs = ps.executeQuery(); 166 | if (rs.next()) { 167 | customer = new UserBean(); 168 | customer.setFName(rs.getString("fname")); 169 | customer.setLName(rs.getString("lname")); 170 | customer.setAddr(rs.getString("addr")); 171 | customer.setMailId(rs.getString("mailid")); 172 | customer.setPhNo(rs.getLong("phno")); 173 | customer.setPWord(rs.getString("pword")); 174 | } else { 175 | throw new TrainException(ResponseCode.UNAUTHORIZED); 176 | } 177 | ps.close(); 178 | } catch (SQLException e) { 179 | System.out.println(e.getMessage()); 180 | throw new TrainException(e.getMessage()); 181 | } 182 | return customer; 183 | } 184 | 185 | } 186 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Train Ticket Reservation System 2 | 3 | - Youtube video for Step by Step Guide on Local Setup: https://www.youtube.com/watch?v=Wd2GlEJJJlw 4 | 5 | 6 | 7 | ### About: 8 | This project is about the Train-Ticket-Reservation-System which is used to view Train Schedule, search trains, Seat availability, Train timings. We can also enquire about fare of different trains. We can get information about train between two stations. We can book seats online. This provides a safe and secure seat reservation system. 9 | ### Online Train Information and Reservation 10 | **This Website is built for following purpose:-** 11 | - View Trains Schedule 12 | - Search Trains 13 | - Seat Availability 14 | - Train Timings 15 | - Fare Enquiry 16 | - Trains Between Stations 17 | - Booking seats online. 18 | - Login and Logout Security 19 | - Password Changes 20 | - Payment Gateway 21 | - Ticket Booking History 22 | 23 | **The Admin have the following access to this website:-** 24 | - Login 25 | - Add Trains 26 | - Update Trains 27 | - Remove or cancle Trains 28 | - View Trains 29 | - Profile Edit 30 | - Logout 31 | 32 | **The Users have the following Access:-** 33 | - Register 34 | - Login 35 | - View Trains 36 | - Check Seat Availability 37 | - Search Trains 38 | - Train Avaiablity and Fare Between Stations 39 | - Books Tickets 40 | - View Booking History 41 | - View Profile 42 | - Update Profile 43 | - Change Password 44 | - Logout 45 | 46 | ### Technologies used:- 47 | 1. Front-End Development: 48 | - HTML 49 | - CSS 50 | - Bootstrap 51 | 52 | 2. Back-End Development 53 | - Java [J2EE] 54 | - JDBC 55 | - Servlet 56 | - Oracle ( SQL ) 57 | 58 | ### ==== Software And Tools Required ====== 59 | - : Git [https://www.youtube.com/watch?v=gv7VPQ4LZ7g] 60 | - : Java JDK 8+ [https://www.youtube.com/watch?v=O9PWH9SeTTE] 61 | - : Eclipse EE [https://www.youtube.com/watch?v=8aDsEV7txXE] 62 | - : Apache Maven [https://www.youtube.com/watch?v=jd2zx3dLjuw] 63 | - : Tomcat v8.0+ [https://youtu.be/mLFPodZO8Iw?t=903] 64 | - : Oracle (SQL) / SQL PLUS [https://www.youtube.com/watch?v=ZYOqykEDSqU] 65 | - : Oracle SQL Developer [https://www.youtube.com/watch?v=2a1JKIGVtd0] 66 | 67 | ### ========== Dummy Database Initialization =========== 68 | 69 | STEP 1: Open SQL Plus OR SQL Developer 70 | 71 | STEP 2: Login and connect to database using administrator username and password 72 | 73 | STEP 3 :Execute the below command first to create a new user: 74 | 75 | ```SQL 76 | 77 | ALTER SESSION SET "_ORACLE_SCRIPT"=TRUE; 78 | CREATE USER RESERVATION IDENTIFIED BY MANAGER; 79 | GRANT DBA TO RESERVATION; 80 | COMMIT; 81 | 82 | ``` 83 | NOTE: If the above command fails for alter session issues, try to remove first line and then execute it. 84 | 85 | STEP 4: Now execute the below sql query in same terminal 86 | 87 | ```SQL 88 | 89 | CONNECT RESERVATION/MANAGER; 90 | CREATE TABLE "RESERVATION"."CUSTOMER" 91 | ( 92 | "MAILID" VARCHAR2(40) PRIMARY KEY, 93 | "PWORD" VARCHAR2(20) NOT NULL, 94 | "FNAME" VARCHAR2(20) NOT NULL, 95 | "LNAME" VARCHAR2(20), 96 | "ADDR" VARCHAR2(100), 97 | "PHNO" NUMBER(12) NOT NULL 98 | ); 99 | 100 | CREATE TABLE "RESERVATION"."ADMIN" 101 | ( 102 | "MAILID" VARCHAR2(40) PRIMARY KEY, 103 | "PWORD" VARCHAR2(20) NOT NULL, 104 | "FNAME" VARCHAR2(20) NOT NULL, 105 | "LNAME" VARCHAR2(20), 106 | "ADDR" VARCHAR2(100), 107 | "PHNO" NUMBER(12) NOT NULL 108 | ); 109 | 110 | 111 | CREATE TABLE "RESERVATION"."TRAIN" 112 | ( 113 | "TR_NO" NUMBER(10) PRIMARY KEY, 114 | "TR_NAME" VARCHAR2(70) NOT NULL, 115 | "FROM_STN" VARCHAR2(20) NOT NULL, 116 | "TO_STN" VARCHAR2(20) NOT NULL, 117 | "SEATS" NUMBER(4) NOT NULL, 118 | "FARE" NUMBER(6,2) NOT NULL 119 | ); 120 | 121 | CREATE TABLE "RESERVATION"."HISTORY" 122 | ( 123 | "TRANSID" VARCHAR2(36) PRIMARY KEY, 124 | "MAILID" VARCHAR2(40) REFERENCES "RESERVATION"."CUSTOMER"(MAILID), 125 | "TR_NO" NUMBER(10), 126 | "DATE" DATE, 127 | "FROM_STN" VARCHAR2(20) NOT NULL, 128 | "TO_STN" VARCHAR2(20) NOT NULL, 129 | "SEATS" NUMBER(3) NOT NULL, 130 | "AMOUNT" NUMBER(8,2) NOT NULL 131 | ); 132 | 133 | COMMIT; 134 | 135 | INSERT INTO RESERVATION.ADMIN VALUES('admin@demo.com','admin','System','Admin','Demo Address 123 colony','9874561230'); 136 | INSERT INTO RESERVATION.CUSTOMER VALUES('shashi@demo.com','shashi','Shashi','Raj','Kolkata, West Bengal',954745222); 137 | 138 | INSERT INTO RESERVATION.TRAIN VALUES(10001,'JODHPUR EXP','HOWRAH','JODHPUR', 152, 490.50); 139 | INSERT INTO RESERVATION.TRAIN VALUES(10002,'YAMUNA EXP','GAYA','DELHI', 52, 550.50); 140 | INSERT INTO RESERVATION.TRAIN VALUES(10003,'NILANCHAL EXP','GAYA','HOWRAH', 92, 451); 141 | INSERT INTO RESERVATION.TRAIN VALUES(10004,'JAN SATABDI EXP','RANCHI','PATNA', 182, 550); 142 | INSERT INTO RESERVATION.TRAIN VALUES(10005,'GANGE EXP','MUMBAI','KERALA', 12, 945); 143 | INSERT INTO RESERVATION.TRAIN VALUES(10006,'GARIB RATH EXP','PATNA','DELHI', 1, 1450.75); 144 | 145 | INSERT INTO RESERVATION.HISTORY VALUES('BBC374-NSDF-4673','shashi@demo.com',10001,TO_DATE('02-FEB-2024'), 'HOWRAH', 'JODHPUR', 2, 981); 146 | INSERT INTO RESERVATION.HISTORY VALUES('BBC375-NSDF-4675','shashi@demo.com',10004,TO_DATE('12-JAN-2024'), 'RANCHI', 'PATNA', 1, 550); 147 | INSERT INTO RESERVATION.HISTORY VALUES('BBC373-NSDF-4674','shashi@demo.com',10006,TO_DATE('22-JULY-2024'), 'PATNA', 'DELHI', 3, 4352.25); 148 | 149 | COMMIT; 150 | ``` 151 | STEP 5: Now Execute the below query one by one to check if the tables are created successfully 152 | ```SQL 153 | SELECT * FROM ADMIN; 154 | SELECT * FROM CUSTOMER; 155 | SELECT * FROM TRAIN; 156 | SELECT * FROM HISTORY; 157 | 158 | ``` 159 | Note: If any of the above commands fails, please try to fix it first and then proceed to next step 160 | 161 | ### ====== Importing and Running the Project Through Eclipse EE =========== 162 | Step 0: Open Eclipse Enterprise Edition. [Install if not available](https://www.youtube.com/watch?v=8aDsEV7txXE) 163 | 164 | Step 1: Click On File > Import > Git > Projects From Git > Clone Uri > Paste The Repository Url: ```https://github.com/shashirajraja/Train-Ticket-Reservation-System.git``` > Next > Select Master Branch > Next > Finish 165 | 166 | Step 2.A: Right Click on Project > Run as > Maven Build > In the goals field enter "clean install" > apply > run 167 | 168 | Step 2.B: Right Click On Project > Build Path > Configure Build Path > Libraries > Remove And Update Any Libraries With Red Mark > Finish 169 | 170 | Step 3: [Only if Tomcat v8.0 is not Configured in Eclipse]: Right Click On Project > Run As > Run On Server > Select Tomcat v8.0 > (Select Tomcat V8.0 Installation Location If Asked) Next > Add > Finish 171 | 172 | Step 4: In The Server Tab > Double Click On Tomcat Server > Ports > Change The Port Number For Http/1.1 To 8083 > Close And Save 173 | 174 | Step 5: Right Click On Project > Run As > Run On Server > Select Tomcat V8.0 > Next > Add All> Done 175 | 176 | Step 6: Check Running The Site At http://localhost:8083/trainbook/ 177 | 178 | Step 7: Default Username And Password For Admin Is "admin@demo.com" And "admin" 179 | 180 | Step 8: Default Username And Password For User Is "shashi@demo.com" And "shashi" 181 | 182 | 183 | 184 | ### The Screenshots of some of the webPages of this project are Here: 185 | 186 | 1. Login Page 187 | Login to Book Trains 188 | 189 | 2. Register New User 190 | Register New User 191 | 192 | 3. User Profile 193 | View User Profile 194 | 195 | 4. Search Trains Between Stations 196 | Search Trains Between Stations 197 | 198 | 5. View Trains 199 | View Available Trains 200 | 201 | 7. Book Trains 202 | Book Trains Project 203 | 204 | 8. Payment Gateway 205 | Pay to Book Trains 206 | 207 | 9. Booked Ticket Information 208 | Show Booked Ticket Details 209 | 210 | 10. Ticket Booking History 211 | All Ticket Booking History 212 | 213 | 11. Fare Enquiry 214 | Fare Enquiry between stations 215 | 216 | 12. Change Password 217 | Change user Password 218 | 219 | 13. Add Trains By Admin 220 | Admin Home 221 | 222 | 223 | #### "Suggestions and project Improvement are Invited" 224 | #### Shashi Raj 225 | ##### Project Leader 226 | --------------------------------------------------------------------------------