diff --git a/.classpath b/.classpath index 288cc9b..178b91b 100644 --- a/.classpath +++ b/.classpath @@ -1,19 +1,22 @@ - - - - - - + - + + - + - + + - + + + + + + + diff --git a/.gitignore b/.gitignore index 84c048a..76daa49 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /build/ +/target/ diff --git a/.project b/.project index df9921e..1864273 100644 --- a/.project +++ b/.project @@ -20,8 +20,14 @@ + + org.eclipse.m2e.core.maven2Builder + + + + org.eclipse.m2e.core.maven2Nature org.eclipse.jem.workbench.JavaEMFNature org.eclipse.wst.common.modulecore.ModuleCoreNature org.eclipse.wst.common.project.facet.core.nature diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 295926d..ddd0785 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -3,5 +3,9 @@ org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.release=disabled org.eclipse.jdt.core.compiler.source=1.8 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 0096d55..4da4a3d 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,8 +1,32 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml index e608538..3329d55 100644 --- a/.settings/org.eclipse.wst.common.project.facet.core.xml +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -1,10 +1,9 @@ - - + diff --git a/.settings/org.eclipse.wst.validation.prefs b/.settings/org.eclipse.wst.validation.prefs new file mode 100644 index 0000000..04cad8c --- /dev/null +++ b/.settings/org.eclipse.wst.validation.prefs @@ -0,0 +1,2 @@ +disabled=06target +eclipse.preferences.version=1 diff --git a/Dummy-Database.md b/Dummy-Database.md index e66856c..63d339e 100644 --- a/Dummy-Database.md +++ b/Dummy-Database.md @@ -1,29 +1,74 @@ ### Just open the Oracle sql command prompt and login to administrator user and copy paste the following codes for creating dummy database: ```SQL -create user reservation identified by manager; +ALTER SESSION SET "_ORACLE_SCRIPT"=TRUE; -grant dba to reservation; +CREATE USER RESERVATION IDENTIFIED BY MANAGER; -commit; +GRANT DBA TO RESERVATION; -connect reservation/manager; +COMMIT; -create table admin6(uname varchar2(40) primary key,name varchar2(40), - pword varchar2(50),mail_id varchar2(60),phone_no varchar2(12)); - -create table train6(tr_no number(10) primary key,tr_name varchar2(70), - from_stn varchar2(20),to_stn varchar2(20),available number(5),fare number(5)); +CONNECT RESERVATION/MANAGER; -create table register(uname varchar2(40) primary key,pword varchar2(50), - fname varchar2(40),lname varchar2(40), - addr varchar2(100), phno varchar2(12), mailid varchar2(60)); +CREATE TABLE "RESERVATION"."CUSTOMER" +( +"MAILID" VARCHAR2(40) PRIMARY KEY, +"PWORD" VARCHAR2(20) NOT NULL, +"FNAME" VARCHAR2(20) NOT NULL, +"LNAME" VARCHAR2(20), +"ADDR" VARCHAR2(100), +"PHNO" NUMBER(12) NOT NULL +); -insert into admin6 values('admin','admin','admin','admin@train.com','9874561230'); -insert into admin6 values('shashi','shashi','admin','shashi@train.com','98323561230'); -insert into train6 values(10101,'Jodhpur Exp','Howrah','Jodhpur',152,450); -insert into train6 values(10102,'Mumbai Mail','Gaya','Mumbai',182,650); -insert into register values('shashi','shashi','Shashi','Raj','Tekari, Gaya, Bihar',954745222,'shashiraj.972@gmail.com'); +CREATE TABLE "RESERVATION"."ADMIN" +( +"MAILID" VARCHAR2(40) PRIMARY KEY, +"PWORD" VARCHAR2(20) NOT NULL, +"FNAME" VARCHAR2(20) NOT NULL, +"LNAME" VARCHAR2(20), +"ADDR" VARCHAR2(100), +"PHNO" NUMBER(12) NOT NULL +); -commit; + +CREATE TABLE "RESERVATION"."TRAIN" +( +"TR_NO" NUMBER(10) PRIMARY KEY, +"TR_NAME" VARCHAR2(70) NOT NULL, +"FROM_STN" VARCHAR2(20) NOT NULL, +"TO_STN" VARCHAR2(20) NOT NULL, +"SEATS" NUMBER(4) NOT NULL, +"FARE" NUMBER(6,2) NOT NULL +); + +CREATE TABLE "RESERVATION"."HISTORY" +( +"TRANSID" VARCHAR2(30) PRIMARY KEY, +"MAILID" VARCHAR2(40) REFERENCES "RESERVATION"."CUSTOMER"(MAILID), +"TR_NO" NUMBER(10), +"DATE" DATE, +"FROM_STN" VARCHAR2(20) NOT NULL, +"TO_STN" VARCHAR2(20) NOT NULL, +"SEATS" NUMBER(3) NOT NULL, +"AMOUNT" NUMBER(8,2) NOT NULL +); + +COMMIT; + +INSERT INTO RESERVATION.ADMIN VALUES('admin@demo.com','admin','System','Admin','Demo Address 123 colony','9874561230'); +INSERT INTO RESERVATION.CUSTOMER VALUES('shashi@demo.com','shashi','Shashi','Raj','Kolkata, West Bengal',954745222); + +INSERT INTO RESERVATION.TRAIN VALUES(10001,'JODHPUR EXP','HOWRAH','JODHPUR', 152, 490.50); +INSERT INTO RESERVATION.TRAIN VALUES(10002,'YAMUNA EXP','GAYA','DELHI', 52, 550.50); +INSERT INTO RESERVATION.TRAIN VALUES(10003,'NILANCHAL EXP','GAYA','HOWRAH', 92, 451); +INSERT INTO RESERVATION.TRAIN VALUES(10004,'JAN SATABDI EXP','RANCHI','PATNA', 182, 550); +INSERT INTO RESERVATION.TRAIN VALUES(10005,'GANGE EXP','MUMBAI','KERALA', 12, 945); +INSERT INTO RESERVATION.TRAIN VALUES(10006,'GARIB RATH EXP','PATNA','DELHI', 1, 1450.75); + +INSERT INTO RESERVATION.HISTORY VALUES('BBC374-NSDF-4673','shashi@demo.com',10001,TO_DATE('02-FEB-2024'), 'HOWRAH', 'JODHPUR', 2, 981); +INSERT INTO RESERVATION.HISTORY VALUES('BBC375-NSDF-4675','shashi@demo.com',10004,TO_DATE('12-JAN-2024'), 'RANCHI', 'PATNA', 1, 550); +INSERT INTO RESERVATION.HISTORY VALUES('BBC373-NSDF-4674','shashi@demo.com',10006,TO_DATE('22-JULY-2024'), 'PATNA', 'DELHI', 3, 4352.25); + +COMMIT; ``` diff --git a/README.md b/README.md index 9a8c474..cd6ecdc 100644 --- a/README.md +++ b/README.md @@ -65,31 +65,76 @@ STEP 2: Login to administrator User as: ```connect /``` STEP 3 :Copy paste the following SQL Query: ```SQL -create user reservation identified by manager; - -grant dba to reservation; - -commit; - -connect reservation/manager; - -create table admin6(uname varchar2(40) primary key,name varchar2(40), - pword varchar2(50),mail_id varchar2(60),phone_no varchar2(12)); - -create table train6(tr_no number(10) primary key,tr_name varchar2(70), - from_stn varchar2(20),to_stn varchar2(20),available number(5),fare number(5)); - -create table register(uname varchar2(40) primary key,pword varchar2(50), - fname varchar2(40),lname varchar2(40), - addr varchar2(100), phno varchar2(12), mailid varchar2(60)); - -insert into admin6 values('admin','admin','admin','admin@train.com','9874561230'); -insert into admin6 values('shashi','shashi','admin','shashi@train.com','98323561230'); -insert into train6 values(10101,'Jodhpur Exp','Howrah','Jodhpur',152,450); -insert into train6 values(10102,'Mumbai Mail','Gaya','Mumbai',182,650); -insert into register values('shashi','shashi','Shashi','Raj','Tekari, Gaya, Bihar',954745222,'shashiraj.972@gmail.com'); - -commit; +ALTER SESSION SET "_ORACLE_SCRIPT"=TRUE; + +CREATE USER RESERVATION IDENTIFIED BY MANAGER; + +GRANT DBA TO RESERVATION; + +COMMIT; + +CONNECT RESERVATION/MANAGER; + +CREATE TABLE "RESERVATION"."CUSTOMER" +( +"MAILID" VARCHAR2(40) PRIMARY KEY, +"PWORD" VARCHAR2(20) NOT NULL, +"FNAME" VARCHAR2(20) NOT NULL, +"LNAME" VARCHAR2(20), +"ADDR" VARCHAR2(100), +"PHNO" NUMBER(12) NOT NULL +); + +CREATE TABLE "RESERVATION"."ADMIN" +( +"MAILID" VARCHAR2(40) PRIMARY KEY, +"PWORD" VARCHAR2(20) NOT NULL, +"FNAME" VARCHAR2(20) NOT NULL, +"LNAME" VARCHAR2(20), +"ADDR" VARCHAR2(100), +"PHNO" NUMBER(12) NOT NULL +); + + +CREATE TABLE "RESERVATION"."TRAIN" +( +"TR_NO" NUMBER(10) PRIMARY KEY, +"TR_NAME" VARCHAR2(70) NOT NULL, +"FROM_STN" VARCHAR2(20) NOT NULL, +"TO_STN" VARCHAR2(20) NOT NULL, +"SEATS" NUMBER(4) NOT NULL, +"FARE" NUMBER(6,2) NOT NULL +); + +CREATE TABLE "RESERVATION"."HISTORY" +( +"TRANSID" VARCHAR2(30) PRIMARY KEY, +"MAILID" VARCHAR2(40) REFERENCES "RESERVATION"."CUSTOMER"(MAILID), +"TR_NO" NUMBER(10), +"DATE" DATE, +"FROM_STN" VARCHAR2(20) NOT NULL, +"TO_STN" VARCHAR2(20) NOT NULL, +"SEATS" NUMBER(3) NOT NULL, +"AMOUNT" NUMBER(8,2) NOT NULL +); + +COMMIT; + +INSERT INTO RESERVATION.ADMIN VALUES('admin@demo.com','admin','System','Admin','Demo Address 123 colony','9874561230'); +INSERT INTO RESERVATION.CUSTOMER VALUES('shashi@demo.com','shashi','Shashi','Raj','Kolkata, West Bengal',954745222); + +INSERT INTO RESERVATION.TRAIN VALUES(10001,'JODHPUR EXP','HOWRAH','JODHPUR', 152, 490.50); +INSERT INTO RESERVATION.TRAIN VALUES(10002,'YAMUNA EXP','GAYA','DELHI', 52, 550.50); +INSERT INTO RESERVATION.TRAIN VALUES(10003,'NILANCHAL EXP','GAYA','HOWRAH', 92, 451); +INSERT INTO RESERVATION.TRAIN VALUES(10004,'JAN SATABDI EXP','RANCHI','PATNA', 182, 550); +INSERT INTO RESERVATION.TRAIN VALUES(10005,'GANGE EXP','MUMBAI','KERALA', 12, 945); +INSERT INTO RESERVATION.TRAIN VALUES(10006,'GARIB RATH EXP','PATNA','DELHI', 1, 1450.75); + +INSERT INTO RESERVATION.HISTORY VALUES('BBC374-NSDF-4673','shashi@demo.com',10001,TO_DATE('02-FEB-2024'), 'HOWRAH', 'JODHPUR', 2, 981); +INSERT INTO RESERVATION.HISTORY VALUES('BBC375-NSDF-4675','shashi@demo.com',10004,TO_DATE('12-JAN-2024'), 'RANCHI', 'PATNA', 1, 550); +INSERT INTO RESERVATION.HISTORY VALUES('BBC373-NSDF-4674','shashi@demo.com',10006,TO_DATE('22-JULY-2024'), 'PATNA', 'DELHI', 3, 4352.25); + +COMMIT; ``` ### ====== Importing and Running the Project Through Eclipse EE =========== @@ -107,9 +152,9 @@ Step 5: Right Click On Project > Run As > Run On Server > Select Tomcat V8.0 > N Step 6: Check Running The Site At http://localhost:8083/trainbook/ -Step 7: Default Username And Password For Admin Is "admin" And "admin" +Step 7: Default Username And Password For Admin Is "admin@demo.com" And "admin" -Step 8: Default Username And Password For User Is "shashi" And "shashi" +Step 8: Default Username And Password For User Is "shashi@demo.com" And "shashi" diff --git a/WebContent/AddTrains.html b/WebContent/AddTrains.html index 1b7fb7b..8951e7b 100644 --- a/WebContent/AddTrains.html +++ b/WebContent/AddTrains.html @@ -10,7 +10,7 @@
-

National InformaTion Railway Tourism Control Hyderabad
[ NITRTC ]

+

National Ticket Booking Spot

diff --git a/WebContent/AdminHome.html b/WebContent/AdminHome.html index 28e6d41..2101148 100644 --- a/WebContent/AdminHome.html +++ b/WebContent/AdminHome.html @@ -10,7 +10,7 @@
-

National InformaTion Railway Tourism Control Hyderabad
[ NITRTC ]

+

National Ticket Booking Spot

diff --git a/WebContent/AdminLogin.html b/WebContent/AdminLogin.html index 5918282..29b3878 100644 --- a/WebContent/AdminLogin.html +++ b/WebContent/AdminLogin.html @@ -88,7 +88,7 @@
-

National InformaTion Railway Tourism Control Hyderabad
[ NITRTC ]

+

National Ticket Booking Spot

Login as User New User @@ -97,7 +97,7 @@

National InformaTion Railway Tourism Control Hyderabad
[ NIT

Admin Login
-
UserName:

+
UserName:

Password:


diff --git a/WebContent/AdminSearchTrain.html b/WebContent/AdminSearchTrain.html index dde595e..bee2a56 100644 --- a/WebContent/AdminSearchTrain.html +++ b/WebContent/AdminSearchTrain.html @@ -10,7 +10,7 @@
-

National InformaTion Railway Tourism Control Hyderabad
[ NITRTC ]

+

National Ticket Booking Spot

diff --git a/WebContent/AdminUpdateTrain.html b/WebContent/AdminUpdateTrain.html index 1dcf756..8b3f068 100644 --- a/WebContent/AdminUpdateTrain.html +++ b/WebContent/AdminUpdateTrain.html @@ -10,7 +10,7 @@
-

National InformaTion Railway Tourism Control Hyderabad
[ NITRTC ]

+

National Ticket Booking Spot

diff --git a/WebContent/Availability.html b/WebContent/Availability.html index f6a7e8a..003fc32 100644 --- a/WebContent/Availability.html +++ b/WebContent/Availability.html @@ -10,7 +10,7 @@
-

National InformaTion Railway Tourism Control Hyderabad
[ NITRTC ]

+

National Ticket Booking Spot

diff --git a/WebContent/BookTrains.html b/WebContent/BookTrains.html index 3fb5558..9f68b14 100644 --- a/WebContent/BookTrains.html +++ b/WebContent/BookTrains.html @@ -10,7 +10,7 @@
-

National InformaTion Railway Tourism Control Hyderabad
[ NITRTC ]

+

National Ticket Booking Spot

diff --git a/WebContent/CancleTrain.html b/WebContent/CancleTrain.html index 67f2780..692678a 100644 --- a/WebContent/CancleTrain.html +++ b/WebContent/CancleTrain.html @@ -10,7 +10,7 @@
-

National InformaTion Railway Tourism Control Hyderabad
[ NITRTC ]

+

National Ticket Booking Spot

diff --git a/WebContent/Fare.html b/WebContent/Fare.html index 585c8d5..98cdae0 100644 --- a/WebContent/Fare.html +++ b/WebContent/Fare.html @@ -10,7 +10,7 @@
-

National InformaTion Railway Tourism Control Hyderabad
[ NITRTC ]

+

National Ticket Booking Spot

diff --git a/WebContent/SearchTrains.html b/WebContent/SearchTrains.html index 1276adf..e57d658 100644 --- a/WebContent/SearchTrains.html +++ b/WebContent/SearchTrains.html @@ -10,7 +10,7 @@
-

National InformaTion Railway Tourism Control Hyderabad
[ NITRTC ]

+

National Ticket Booking Spot

diff --git a/WebContent/TrainBwStn.html b/WebContent/TrainBwStn.html index 6c5d21d..91088fc 100644 --- a/WebContent/TrainBwStn.html +++ b/WebContent/TrainBwStn.html @@ -10,7 +10,7 @@
-

National InformaTion Railway Tourism Control Hyderabad
[ NITRTC ]

+

National Ticket Booking Spot

diff --git a/WebContent/UserHome.html b/WebContent/UserHome.html index cf5e374..34923d0 100644 --- a/WebContent/UserHome.html +++ b/WebContent/UserHome.html @@ -10,7 +10,7 @@
-

National InformaTion Railway Tourism Control Hyderabad
[ NITRTC ]

+

National Ticket Booking Spot

diff --git a/WebContent/UserHome_Css.css b/WebContent/UserHome_Css.css index 14fbf30..fd13356 100644 --- a/WebContent/UserHome_Css.css +++ b/WebContent/UserHome_Css.css @@ -11,7 +11,7 @@ .hd{ text-align: center; padding:10px; - margin-left: 5%; + margin-left: 10%; margin-right: 5%; color:#cc0066; font-weight: bold; diff --git a/WebContent/UserLogin.html b/WebContent/UserLogin.html index 89ec421..9a479f4 100644 --- a/WebContent/UserLogin.html +++ b/WebContent/UserLogin.html @@ -88,7 +88,7 @@
-

National InformaTion Railway Tourism Control Hyderabad
[ NITRTC ]

+

National Ticket Booking Spot

Login as User New User Register @@ -97,7 +97,7 @@

National InformaTion Railway Tourism Control Hyderabad
[ NITR

User Login
-
UserName:

+
UserName:

Password:


diff --git a/WebContent/UserRegister.html b/WebContent/UserRegister.html index 5c63868..c547fd3 100644 --- a/WebContent/UserRegister.html +++ b/WebContent/UserRegister.html @@ -88,7 +88,7 @@
-

National InformaTion Railway Tourism Control Hyderabad
[ NITRTC ]

+

National Ticket Booking Spot

Login as User New User @@ -106,13 +106,12 @@

National InformaTion Railway Tourism Control Hyderabad
[ NITR - Username :

+ Email Id :

Password :

FirstName:

Last Name:

- Addrress :

+ Address :

Phone No :

- Email Id :

Photo :

diff --git a/WebContent/UserViewTrains.html b/WebContent/UserViewTrains.html index 6e9ff61..028b946 100644 --- a/WebContent/UserViewTrains.html +++ b/WebContent/UserViewTrains.html @@ -2,7 +2,7 @@ - Admin Home + View Trains + + + + + \ No newline at end of file diff --git a/WebContent/index.html b/WebContent/index.html index 31024c2..588f215 100644 --- a/WebContent/index.html +++ b/WebContent/index.html @@ -87,7 +87,7 @@
-

National InformaTion Railway Tourism Control [ NITRTC Hyderabad ]

+

National Ticket Booking Spot

Home Profile diff --git a/pom.xml b/pom.xml index b912d5c..c61dada 100644 --- a/pom.xml +++ b/pom.xml @@ -1,10 +1,8 @@ - + 4.0.0 TrainBook TrainBook - 0.0.1-SNAPSHOT + 1.0.0-SNAPSHOT war src diff --git a/src/com/shashi/beans/AdminBean.java b/src/com/shashi/beans/AdminBean.java index 8f0c6af..19c8b52 100644 --- a/src/com/shashi/beans/AdminBean.java +++ b/src/com/shashi/beans/AdminBean.java @@ -1,63 +1,60 @@ package com.shashi.beans; -import java.io.*; + +import java.io.Serializable; + @SuppressWarnings("serial") -public class AdminBean implements Serializable{ - private String uName,pWord,fName,lName,addR,mailId; +public class AdminBean implements Serializable { + private String pWord, fName, lName, addR, mailId; private long phNo; - public AdminBean() {} - public void setUName(String uName) - { - this.uName=uName; + + public AdminBean() { } - public String getUName() - { - return uName; - } - public void setPWord(String pWord) - { + + public void setPWord(String pWord) { this.pWord = pWord; } - public String getPWord() - { + + public String getPWord() { return pWord; } - public void setFName(String fName) - { + + public void setFName(String fName) { this.fName = fName; } + public String getFName() { return fName; } - public void setLName(String lName) - { + + public void setLName(String lName) { this.lName = lName; } - public String getLName() - { + + public String getLName() { return lName; } - public void setAddr(String addR) - { + + public void setAddr(String addR) { this.addR = addR; } - public String getAddr() - { + + public String getAddr() { return addR; } - public void setMailId(String mailId) - { + + public void setMailId(String mailId) { this.mailId = mailId; } - public String getMailId() - { + + public String getMailId() { return mailId; } - public void setPhNo(long phNo) - { + + public void setPhNo(long phNo) { this.phNo = phNo; } - public long getPhNo() - { + + public long getPhNo() { return phNo; } } diff --git a/src/com/shashi/beans/TrainException.java b/src/com/shashi/beans/TrainException.java new file mode 100644 index 0000000..f7edf02 --- /dev/null +++ b/src/com/shashi/beans/TrainException.java @@ -0,0 +1,63 @@ +package com.shashi.beans; + +import java.io.IOException; + +import com.shashi.constant.ResponseCode; + +public class TrainException extends IOException { + + /** + * + */ + private static final long serialVersionUID = 1L; + + private String errorCode; + private String errorMessage; + private int statusCode; + + public TrainException(ResponseCode errorCodes) { + super(errorCodes.getMessage()); + this.statusCode = errorCodes.getCode(); + this.errorMessage = errorCodes.getMessage(); + this.setErrorCode(errorCodes.name()); + } + + public TrainException(String errorMessage) { + super(errorMessage); + this.errorCode = "BAD_REQUEST"; + this.setStatusCode(400); + this.errorMessage = errorMessage; + } + + public TrainException(int statusCode, String errorCode, String errorMessage) { + super(errorMessage); + this.statusCode = statusCode; + this.errorCode = errorCode; + this.errorMessage = errorMessage; + } + + public String getErrorCode() { + return errorCode; + } + + public void setErrorCode(String errorCode) { + this.errorCode = errorCode; + } + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public int getStatusCode() { + return statusCode; + } + + public void setStatusCode(int statusCode) { + this.statusCode = statusCode; + } + +} diff --git a/src/com/shashi/beans/TransBean.java b/src/com/shashi/beans/TransBean.java index e7a9e04..c76cb7d 100644 --- a/src/com/shashi/beans/TransBean.java +++ b/src/com/shashi/beans/TransBean.java @@ -2,64 +2,62 @@ import java.io.*; @SuppressWarnings("serial") public class TransBean implements Serializable{ - private String transId,uName,fromStn,toStn,time; - private long seatNo,trainNo; - public void setUName(String uName) - { - this.uName = uName; - } - public String getUName() - { - return uName; - } - public void setTranId(String transId) - { + private String transId,mailId,fromStn,toStn,time; + private long seatNo,trainNo, quantity; + private double amount; + public String getTransId() { + return transId; + } + public void setTransId(String transId) { this.transId = transId; } - public void setTrainNo(long trainNo) - { - this.trainNo = trainNo; + public String getMailId() { + return mailId; + } + public void setMailId(String mailId) { + this.mailId = mailId; + } + public String getFromStn() { + return fromStn; } - public void setFromStn(String fromStn) - { + public void setFromStn(String fromStn) { this.fromStn = fromStn; } - public void setToStn(String toStn) - { + public String getToStn() { + return toStn; + } + public void setToStn(String toStn) { this.toStn = toStn; } - public void setTime(String time) - { + public String getTime() { + return time; + } + public void setTime(String time) { this.time = time; } - public void setSeats(long seatNo) - { + public long getSeatNo() { + return seatNo; + } + public void setSeatNo(long seatNo) { this.seatNo = seatNo; } - - public String getTranId() - { - return transId ; + public long getTrainNo() { + return trainNo; } - public long getTrainNo() - { - return trainNo ; + public void setTrainNo(long trainNo) { + this.trainNo = trainNo; } - public String getFromStn() - { - return fromStn ; + public long getQuantity() { + return quantity; } - public String getToStn() - { - return toStn ; + public void setQuantity(long quantity) { + this.quantity = quantity; } - public String getTime() - { - return time ; + public double getAmount() { + return amount; } - public long getSeats() - { - return seatNo ; + public void setAmount(double amount) { + this.amount = amount; } - + } diff --git a/src/com/shashi/beans/UserBean.java b/src/com/shashi/beans/UserBean.java index fa12cd9..276e370 100644 --- a/src/com/shashi/beans/UserBean.java +++ b/src/com/shashi/beans/UserBean.java @@ -3,18 +3,10 @@ import java.sql.Blob; @SuppressWarnings("serial") public class UserBean implements Serializable{ - private String uName,pWord,fName,lName,addR,mailId; + private String pWord,fName,lName,addR,mailId; private long phNo; private Blob photo; public UserBean() {} - public void setUName(String uName) - { - this.uName=uName; - } - public String getUName() - { - return uName; - } public void setPWord(String pWord) { this.pWord = pWord; diff --git a/src/com/shashi/constant/ResponseCode.java b/src/com/shashi/constant/ResponseCode.java new file mode 100644 index 0000000..4c141e1 --- /dev/null +++ b/src/com/shashi/constant/ResponseCode.java @@ -0,0 +1,42 @@ +package com.shashi.constant; + +import java.util.Arrays; +import java.util.Optional; + +public enum ResponseCode { + + SUCCESS(200, "OK"), + FAILURE(422, "Unprocessible Entity, Failed to Process"), + PAGE_NOT_FOUND(404, "The Page You are Searching For is Not available"), + ACCESS_DENIED(403, "Please Login First to continue"), + BAD_REQUEST(400, "Bad Request, Please Try Again"), + INTERNAL_SERVER_ERROR(500, "Internal Server Error, Try Again!!"), + DATABASE_CONNECTION_FAILURE(406, + "Unable to Connect to DB, Please Check your db credentials in application.properties"), + METHOD_NOT_ALLOWED(405, "Requested HTTP method is not supported by this URL"), + + ; + + private final String message; + private final int code; + + ResponseCode(int code, String message) { + this.message = message; + this.code = code; + } + + public String getMessage() { + return message; + } + + public int getCode() { + return code; + } + + // Reverse lookup methods + public static Optional getMessageByStatusCode(int statusCode) { + return Arrays.stream(ResponseCode.values()) + .filter(error -> error.getCode() == statusCode) + .findFirst(); + } +} diff --git a/src/com/shashi/servlets/AdminAddTrain.java b/src/com/shashi/servlets/AdminAddTrain.java index c35677c..ffe8593 100644 --- a/src/com/shashi/servlets/AdminAddTrain.java +++ b/src/com/shashi/servlets/AdminAddTrain.java @@ -1,14 +1,27 @@ package com.shashi.servlets; -import java.io.*; -import javax.servlet.*; -import javax.servlet.http.*; -import com.shashi.utility.DBConnection; +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; -import java.sql.*; -@SuppressWarnings("serial") -public class AdminAddTrain extends HttpServlet{ +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.shashi.beans.TrainException; +import com.shashi.utility.DBUtil; + +public class AdminAddTrain extends HttpServlet { + /** + * + */ + private static final long serialVersionUID = 1L; /** * * @param req @@ -16,40 +29,38 @@ public class AdminAddTrain extends HttpServlet{ * @throws IOException * @throws ServletException */ - protected void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException - { + protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); PrintWriter pw = res.getWriter(); Cookie ck[] = req.getCookies(); - if(ck!=null) { + if (ck != null) { String uName = ck[0].getValue(); - String pWord = ck[1].getValue(); - if(!uName.equals("")||uName!=null) { + //String pWord = ck[1].getValue(); + if (!uName.equals("") || uName != null) { try { - Connection con = DBConnection.getCon(); - PreparedStatement ps = con.prepareStatement("insert into train6 values(?,?,?,?,?,?)"); + Connection con = DBUtil.getCon(); + PreparedStatement ps = con.prepareStatement("insert into train values(?,?,?,?,?,?)"); ps.setLong(1, Long.parseLong(req.getParameter("trainno"))); - ps.setString(2,req.getParameter("trainname")); - ps.setString(3, req.getParameter("fromstation")); - ps.setString(4, req.getParameter("tostation")); + ps.setString(2, req.getParameter("trainname").toUpperCase()); + ps.setString(3, req.getParameter("fromstation").toUpperCase()); + ps.setString(4, req.getParameter("tostation").toUpperCase()); ps.setLong(5, Long.parseLong(req.getParameter("available"))); - ps.setLong(6,Long.parseLong(req.getParameter("fare"))); + ps.setDouble(6, Double.parseDouble(req.getParameter("fare"))); ResultSet rs = ps.executeQuery(); - if(rs.next()) { + if (rs.next()) { RequestDispatcher rd = req.getRequestDispatcher("AddTrains.html"); rd.include(req, res); pw.println("
Train Added Successfully!
"); - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("AddTrains.html"); rd.include(req, res); pw.println("
Error in filling the train Detail
"); } + } catch (Exception e) { + throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); } - catch(Exception e) {} } - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("AdminLogin.html"); rd.include(req, res); pw.println("
Please Login first !
"); diff --git a/src/com/shashi/servlets/AdminCancleTrain.java b/src/com/shashi/servlets/AdminCancleTrain.java index a593fbf..38020c3 100644 --- a/src/com/shashi/servlets/AdminCancleTrain.java +++ b/src/com/shashi/servlets/AdminCancleTrain.java @@ -1,13 +1,26 @@ package com.shashi.servlets; -import java.io.*; -import javax.servlet.*; -import javax.servlet.http.*; -import com.shashi.utility.DBConnection; +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; -import java.sql.*; -@SuppressWarnings("serial") -public class AdminCancleTrain extends HttpServlet{ +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.shashi.beans.TrainException; +import com.shashi.utility.DBUtil; + +public class AdminCancleTrain extends HttpServlet { + + /** + * + */ + private static final long serialVersionUID = 1L; /** * @@ -16,36 +29,36 @@ public class AdminCancleTrain extends HttpServlet{ * @throws IOException * @throws ServletException */ - protected void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException - { + protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); PrintWriter pw = res.getWriter(); Cookie ck[] = req.getCookies(); - if(ck!=null) { + if (ck != null) { String uName = ck[0].getValue(); - String pWord = ck[1].getValue(); - if(!uName.equals("")||uName!=null) { + // String pWord = ck[1].getValue(); + if (!uName.equals("") || uName != null) { try { - Connection con = DBConnection.getCon(); - PreparedStatement ps = con.prepareStatement("delete from train6 where tr_no=?"); - ps.setLong(1,Long.parseLong(req.getParameter("trainno"))); + Connection con = DBUtil.getCon(); + PreparedStatement ps = con.prepareStatement("delete from train where tr_no=?"); + ps.setLong(1, Long.parseLong(req.getParameter("trainno"))); int k = ps.executeUpdate(); - if(k==1) { + if (k == 1) { RequestDispatcher rd = req.getRequestDispatcher("CancleTrain.html"); rd.include(req, res); - pw.println("
Train number "+req.getParameter("trainno")+" has been Cancelled Successfully.
"); - } - else { + pw.println("
Train number " + req.getParameter("trainno") + + " has been Cancelled Successfully.
"); + } else { RequestDispatcher rd = req.getRequestDispatcher("CancleTrain.html"); rd.include(req, res); - pw.println("
Train No."+req.getParameter("trainno")+" is Not Available !
"); + pw.println("
Train No." + req.getParameter("trainno") + + " is Not Available !
"); } + } catch (Exception e) { + throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); } - catch(Exception e) {} - + } - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("AdminLogin.html"); rd.include(req, res); pw.println("
Please Login first !
"); diff --git a/src/com/shashi/servlets/AdminCancleTrainFwd.java b/src/com/shashi/servlets/AdminCancleTrainFwd.java index 7ca1e6b..3c5d300 100644 --- a/src/com/shashi/servlets/AdminCancleTrainFwd.java +++ b/src/com/shashi/servlets/AdminCancleTrainFwd.java @@ -1,9 +1,21 @@ package com.shashi.servlets; -import java.io.*; -import javax.servlet.*; -import javax.servlet.http.*; -@SuppressWarnings("serial") -public class AdminCancleTrainFwd extends HttpServlet{ + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class AdminCancleTrainFwd extends HttpServlet { + /** + * + */ + private static final long serialVersionUID = 1L; + /** * * @param req @@ -11,19 +23,17 @@ public class AdminCancleTrainFwd extends HttpServlet{ * @throws IOException * @throws ServletException */ - protected void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException - { + protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); PrintWriter pw = res.getWriter(); Cookie ck[] = req.getCookies(); - if(ck!=null) { + if (ck != null) { String uName = ck[0].getValue(); - if(!uName.equals("")||uName!=null) { + if (!uName.equals("") || uName != null) { RequestDispatcher rd = req.getRequestDispatcher("CancleTrain.html"); rd.forward(req, res); } - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("AdminLogin.html"); rd.include(req, res); pw.println("
Please Login first !
"); diff --git a/src/com/shashi/servlets/AdminLogin.java b/src/com/shashi/servlets/AdminLogin.java index 30d2baf..69b58ef 100644 --- a/src/com/shashi/servlets/AdminLogin.java +++ b/src/com/shashi/servlets/AdminLogin.java @@ -1,13 +1,24 @@ package com.shashi.servlets; -import java.io.*; -import java.sql.*; -import javax.servlet.*; -import javax.servlet.http.*; +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.shashi.beans.TrainException; import com.shashi.beans.UserBean; -import com.shashi.utility.DBConnection; +import com.shashi.utility.DBUtil; + @SuppressWarnings("serial") -public class AdminLogin extends HttpServlet{ +public class AdminLogin extends HttpServlet { /** * @@ -16,49 +27,48 @@ public class AdminLogin extends HttpServlet{ * @throws IOException * @throws ServletException */ - protected void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException - { + protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { PrintWriter pw = res.getWriter(); res.setContentType("text/html"); String uName = req.getParameter("uname"); String pWord = req.getParameter("pword"); try { - Connection con = DBConnection.getCon(); - - PreparedStatement ps = con.prepareStatement("select * from admin6 where uname=? and pword=?"); + Connection con = DBUtil.getCon(); + + PreparedStatement ps = con.prepareStatement("select * from admin where mailid=? and pword=?"); ps.setString(1, uName); ps.setString(2, pWord); ResultSet rs = ps.executeQuery(); - if(rs.next()) - { + if (rs.next()) { + System.out.println("Valid "); UserBean ub = new UserBean(); - ub.setUName(rs.getString("uname")); - ub.setFName(rs.getString("name")); - //ub.setLName(rs.getString("lname")); +// ub.setUName(rs.getString("uname")); + ub.setFName(rs.getString("fname")); + ub.setLName(rs.getString("lname")); ub.setPWord(rs.getString("pword")); - //ub.setAddr(rs.getString("addr")); - ub.setMailId(rs.getString("mail_id")); - ub.setPhNo(Long.parseLong(rs.getString("phone_no"))); - - Cookie ck1 = new Cookie("ckname",uName); + ub.setAddr(rs.getString("addr")); + ub.setMailId(rs.getString("mailid")); + ub.setPhNo(Long.parseLong(rs.getString("phno"))); + + Cookie ck1 = new Cookie("ckname", uName); res.addCookie(ck1); - Cookie ck2 = new Cookie("ckpwd",pWord); + Cookie ck2 = new Cookie("ckpwd", pWord); res.addCookie(ck2); - - RequestDispatcher rd = req.getRequestDispatcher("AdminHome.html"); - rd.include(req, res); - pw.println("
Hello, "+uName+" ! Welcome
"); - pw.println("
Hi ! Here You can Manage Train Information as per Your Requirement
"); - - } - else - { + + RequestDispatcher rd = req.getRequestDispatcher("AdminHome.html"); + rd.include(req, res); + pw.println("
Hello, " + uName + " ! Welcome
"); + pw.println("
Hi ! Here You can Manage Train Information as per Your Requirement
"); + + } else { + System.out.println("Invalid "); RequestDispatcher rd = req.getRequestDispatcher("AdminLogin.html"); rd.include(req, res); pw.println("
Invalid Username Or Password !
"); } + } catch (Exception e) { + throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); } - catch(Exception e) {} } } diff --git a/src/com/shashi/servlets/AdminLogoutServlet.java b/src/com/shashi/servlets/AdminLogoutServlet.java index 7d80312..7500147 100644 --- a/src/com/shashi/servlets/AdminLogoutServlet.java +++ b/src/com/shashi/servlets/AdminLogoutServlet.java @@ -1,9 +1,17 @@ package com.shashi.servlets; -import java.io.*; -import javax.servlet.*; -import javax.servlet.http.*; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + @SuppressWarnings("serial") -public class AdminLogoutServlet extends HttpServlet{ +public class AdminLogoutServlet extends HttpServlet { /** * @@ -12,23 +20,21 @@ public class AdminLogoutServlet extends HttpServlet{ * @throws ServletException * @throws IOException */ - protected void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException - { + protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter pw = res.getWriter(); Cookie ck[] = req.getCookies(); - if(ck!=null) { - Cookie ck1 = new Cookie("ckname",""); + if (ck != null) { + Cookie ck1 = new Cookie("ckname", ""); ck1.setMaxAge(0); res.addCookie(ck1); - Cookie ck2 = new Cookie("ckpwd",""); + Cookie ck2 = new Cookie("ckpwd", ""); ck2.setMaxAge(0); res.addCookie(ck2); RequestDispatcher rd = req.getRequestDispatcher("AdminLogin.html"); rd.include(req, res); pw.println("
You have been successfully logged out !
"); - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("AdminLogin.html"); rd.include(req, res); pw.println("
You are Already Logged Out !
"); diff --git a/src/com/shashi/servlets/AdminSearchTrain.java b/src/com/shashi/servlets/AdminSearchTrain.java index b250bf0..2217244 100644 --- a/src/com/shashi/servlets/AdminSearchTrain.java +++ b/src/com/shashi/servlets/AdminSearchTrain.java @@ -1,13 +1,23 @@ package com.shashi.servlets; -import java.io.*; -import javax.servlet.*; -import javax.servlet.http.*; -import com.shashi.utility.DBConnection; +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.shashi.beans.TrainException; +import com.shashi.utility.DBUtil; -import java.sql.*; @SuppressWarnings("serial") -public class AdminSearchTrain extends HttpServlet{ +public class AdminSearchTrain extends HttpServlet { /** * @@ -16,46 +26,43 @@ public class AdminSearchTrain extends HttpServlet{ * @throws IOException * @throws ServletException */ - protected void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException - { + protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); PrintWriter pw = res.getWriter(); Cookie ck[] = req.getCookies(); - if(ck!=null) { + if (ck != null) { String uName = ck[0].getValue(); - String pWord = ck[1].getValue(); - if(!uName.equals("")||uName!=null) { +// String pWord = ck[1].getValue(); + if (!uName.equals("") || uName != null) { try { - Connection con = DBConnection.getCon(); - PreparedStatement ps = con.prepareStatement("Select * from train6 where tr_no=?"); - ps.setLong(1,Long.parseLong(req.getParameter("trainnumber"))); + Connection con = DBUtil.getCon(); + PreparedStatement ps = con.prepareStatement("Select * from train where tr_no=?"); + ps.setLong(1, Long.parseLong(req.getParameter("trainnumber"))); ResultSet rs = ps.executeQuery(); - if(rs.next()) { + if (rs.next()) { RequestDispatcher rd = req.getRequestDispatcher("AdminSearchTrain.html"); rd.include(req, res); pw.println("
Searched Train Detail
"); - pw.println("
" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "
Train Name :"+rs.getString("tr_name")+"
Train Number :"+rs.getLong("tr_no")+"
From Station :"+rs.getString("from_Stn")+"
To Station :"+rs.getString("to_Stn")+"
Available Seats:"+rs.getLong("available")+"
Fare (INR) :"+rs.getLong("fare")+" RS
" - + "
"); - } - else { + pw.println("
" + "" + "" + + "" + + "" + "" + "" + "" + "
Train Name :" + + rs.getString("tr_name") + "
Train Number :" + rs.getLong("tr_no") + "
From Station :" + rs.getString("from_Stn") + + "
To Station :" + rs.getString("to_Stn") + + "
Available Seats:" + + rs.getLong("seats") + "
Fare (INR) :" + + rs.getLong("fare") + " RS
" + "
"); + } else { RequestDispatcher rd = req.getRequestDispatcher("AdminSearchTrain.html"); rd.include(req, res); - pw.println("
Train No."+req.getParameter("trainnumber")+" is Not Available !
"); + pw.println("
Train No." + req.getParameter("trainnumber") + + " is Not Available !
"); } + } catch (Exception e) { + throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); } - catch(Exception e) {} - + } - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("AdminLogin.html"); rd.include(req, res); pw.println("
Please Login first !
"); diff --git a/src/com/shashi/servlets/AdminSearchTrainFwd.java b/src/com/shashi/servlets/AdminSearchTrainFwd.java index f9d4d91..1139127 100644 --- a/src/com/shashi/servlets/AdminSearchTrainFwd.java +++ b/src/com/shashi/servlets/AdminSearchTrainFwd.java @@ -1,9 +1,17 @@ package com.shashi.servlets; -import java.io.*; -import javax.servlet.*; -import javax.servlet.http.*; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + @SuppressWarnings("serial") -public class AdminSearchTrainFwd extends HttpServlet{ +public class AdminSearchTrainFwd extends HttpServlet { /** * @@ -12,19 +20,17 @@ public class AdminSearchTrainFwd extends HttpServlet{ * @throws IOException * @throws ServletException */ - protected void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException - { + protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); PrintWriter pw = res.getWriter(); Cookie ck[] = req.getCookies(); - if(ck!=null) { + if (ck != null) { String uName = ck[0].getValue(); - if(!uName.equals("")||uName!=null) { + if (!uName.equals("") || uName != null) { RequestDispatcher rd = req.getRequestDispatcher("AdminSearchTrain.html"); rd.forward(req, res); } - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("UserLogin.html"); rd.include(req, res); pw.println("
Please Login first !
"); diff --git a/src/com/shashi/servlets/AdminTrainUpdate.java b/src/com/shashi/servlets/AdminTrainUpdate.java index 5855d71..65c3fff 100644 --- a/src/com/shashi/servlets/AdminTrainUpdate.java +++ b/src/com/shashi/servlets/AdminTrainUpdate.java @@ -1,12 +1,23 @@ package com.shashi.servlets; -import java.io.*; -import java.sql.*; -import javax.servlet.*; -import javax.servlet.http.*; -import com.shashi.utility.DBConnection; +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.shashi.beans.TrainException; +import com.shashi.utility.DBUtil; + @SuppressWarnings("serial") -public class AdminTrainUpdate extends HttpServlet{ +public class AdminTrainUpdate extends HttpServlet { /** * @@ -15,48 +26,51 @@ public class AdminTrainUpdate extends HttpServlet{ * @throws IOException * @throws ServletException */ - protected void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException - { + protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); PrintWriter pw = res.getWriter(); Cookie ck[] = req.getCookies(); - if(ck!=null) { + if (ck != null) { String uName = ck[0].getValue(); - String pWord = ck[1].getValue(); - if(!uName.equals("")||uName!=null) { - try { - Connection con = DBConnection.getCon(); - long trNo = Long.parseLong(req.getParameter("trainnumber")); - PreparedStatement ps = con.prepareStatement("select * from train6 where tr_no=?"); - ps.setLong(1, trNo); - ResultSet rs = ps.executeQuery(); - if(rs.next()) { +// String pWord = ck[1].getValue(); + if (!uName.equals("") || uName != null) { + try { + Connection con = DBUtil.getCon(); + long trNo = Long.parseLong(req.getParameter("trainnumber")); + PreparedStatement ps = con.prepareStatement("select * from train where tr_no=?"); + ps.setLong(1, trNo); + ResultSet rs = ps.executeQuery(); + if (rs.next()) { RequestDispatcher rd = req.getRequestDispatcher("AdminHome.html"); rd.include(req, res); pw.println("
Train Schedule Update
"); - pw.println("
" - + "" - + "" - + "" - + "" - + "" - + "" - + "" + pw.println("
" + "
Train No :
Train Name :
From Station :
To Station :
Available seats:
Fare (INR) :
" + + "" + + "" + + "" + + "" + + "" + + "" + "" - + "
Train No :
Train Name :
From Station :
To Station :
Available seats:
Fare (INR) :
" - + "
"); - } - else { - RequestDispatcher rd = req.getRequestDispatcher("AdminUpdateTrain.html"); - rd.include(req, res); - pw.println("
Train Not Available
"); - } + + "" + "
"); + } else { + RequestDispatcher rd = req.getRequestDispatcher("AdminUpdateTrain.html"); + rd.include(req, res); + pw.println("
Train Not Available
"); } - catch(Exception e) {} - + } catch (Exception e) { + throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); + + } + } - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("AdminLogin.html"); rd.include(req, res); pw.println("
Please Login first !
"); diff --git a/src/com/shashi/servlets/AdminTrainUpdateFwd.java b/src/com/shashi/servlets/AdminTrainUpdateFwd.java index cd4db54..512b9c0 100644 --- a/src/com/shashi/servlets/AdminTrainUpdateFwd.java +++ b/src/com/shashi/servlets/AdminTrainUpdateFwd.java @@ -1,9 +1,17 @@ package com.shashi.servlets; -import java.io.*; -import javax.servlet.*; -import javax.servlet.http.*; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + @SuppressWarnings("serial") -public class AdminTrainUpdateFwd extends HttpServlet{ +public class AdminTrainUpdateFwd extends HttpServlet { /** * @@ -12,19 +20,17 @@ public class AdminTrainUpdateFwd extends HttpServlet{ * @throws IOException * @throws ServletException */ - protected void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException - { + protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); PrintWriter pw = res.getWriter(); Cookie ck[] = req.getCookies(); - if(ck!=null) { + if (ck != null) { String uName = ck[0].getValue(); - if(!uName.equals("")||uName!=null) { + if (!uName.equals("") || uName != null) { RequestDispatcher rd = req.getRequestDispatcher("AdminUpdateTrain.html"); rd.forward(req, res); } - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("AdminLogin.html"); rd.include(req, res); pw.println("
Please Login first !
"); diff --git a/src/com/shashi/servlets/AdminViewLinkFwd.java b/src/com/shashi/servlets/AdminViewLinkFwd.java index 40ac7cb..bbd9fd9 100644 --- a/src/com/shashi/servlets/AdminViewLinkFwd.java +++ b/src/com/shashi/servlets/AdminViewLinkFwd.java @@ -1,13 +1,23 @@ package com.shashi.servlets; -import java.io.*; -import javax.servlet.*; -import javax.servlet.http.*; -import com.shashi.utility.DBConnection; +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.shashi.beans.TrainException; +import com.shashi.utility.DBUtil; -import java.sql.*; @SuppressWarnings("serial") -public class AdminViewLinkFwd extends HttpServlet{ +public class AdminViewLinkFwd extends HttpServlet { /** * @@ -16,48 +26,47 @@ public class AdminViewLinkFwd extends HttpServlet{ * @throws IOException * @throws ServletException */ - protected void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException - { + protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); PrintWriter pw = res.getWriter(); Cookie ck[] = req.getCookies(); - if(ck!=null) { + if (ck != null) { String uName = ck[0].getValue(); - String pWord = ck[1].getValue(); - if(!uName.equals("")||uName!=null) { + //String pWord = ck[1].getValue(); + if (!uName.equals("") || uName != null) { try { - Connection con = DBConnection.getCon(); - PreparedStatement ps = con.prepareStatement("Select * from train6 where tr_no=? and from_stn=? and to_stn=?"); - ps.setLong(1,Long.parseLong(req.getParameter("trainNo"))); - ps.setString(2, req.getParameter("fromStn")); - ps.setString(3, req.getParameter("toStn")); + Connection con = DBUtil.getCon(); + PreparedStatement ps = con + .prepareStatement("Select * from train where tr_no=? and from_stn=? and to_stn=?"); + ps.setLong(1, Long.parseLong(req.getParameter("trainNo"))); + ps.setString(2, req.getParameter("fromStn").toUpperCase()); + ps.setString(3, req.getParameter("toStn").toUpperCase()); ResultSet rs = ps.executeQuery(); - if(rs.next()) { + if (rs.next()) { RequestDispatcher rd = req.getRequestDispatcher("AdminHome.html"); rd.include(req, res); pw.println("
Selected Train Detail
"); - pw.println("
" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "
Train Name :"+rs.getString("tr_name")+"
Train Number :"+rs.getLong("tr_no")+"
From Station :"+rs.getString("from_Stn")+"
To Station :"+rs.getString("to_Stn")+"
Available Seats:"+rs.getLong("available")+"
Fare (INR) :"+rs.getLong("fare")+" RS
" - + "
"); - } - else { + pw.println("
" + "" + "" + + "" + + "" + "" + "" + "" + "
Train Name :" + + rs.getString("tr_name") + "
Train Number :" + rs.getLong("tr_no") + "
From Station :" + rs.getString("from_Stn") + + "
To Station :" + rs.getString("to_Stn") + + "
Available Seats:" + + rs.getLong("seats") + "
Fare (INR) :" + + rs.getLong("fare") + " RS
" + "
"); + } else { RequestDispatcher rd = req.getRequestDispatcher("AdminSearchTrains.html"); rd.include(req, res); - pw.println("
Train No."+req.getParameter("trainnumber")+" is Not Available !
"); + pw.println("
Train No." + req.getParameter("trainnumber") + + " is Not Available !
"); } + } catch (Exception e) { + throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); + } - catch(Exception e) {} - + } - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("AdminLogin.html"); rd.include(req, res); pw.println("
Please Login first !
"); diff --git a/src/com/shashi/servlets/AdminViewTrainFwd.java b/src/com/shashi/servlets/AdminViewTrainFwd.java index 1173c4b..5ebb733 100644 --- a/src/com/shashi/servlets/AdminViewTrainFwd.java +++ b/src/com/shashi/servlets/AdminViewTrainFwd.java @@ -1,26 +1,35 @@ package com.shashi.servlets; -import java.io.*; -import java.sql.*; -import javax.servlet.*; -import javax.servlet.http.*; -import com.shashi.utility.DBConnection; +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.shashi.beans.TrainException; +import com.shashi.utility.DBUtil; + @SuppressWarnings("serial") -public class AdminViewTrainFwd extends HttpServlet{ - protected void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException - { +public class AdminViewTrainFwd extends HttpServlet { + protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); PrintWriter pw = res.getWriter(); Cookie ck[] = req.getCookies(); - if(ck!=null) { + if (ck != null) { String uName = ck[0].getValue(); - if(!uName.equals("")||uName!=null) { + if (!uName.equals("") || uName != null) { try { - Connection con = DBConnection.getCon(); - PreparedStatement ps = con.prepareStatement("Select * from train6"); + Connection con = DBUtil.getCon(); + PreparedStatement ps = con.prepareStatement("Select * from train"); ResultSet rs = ps.executeQuery(); - if(rs.next()) - { + if (rs.next()) { RequestDispatcher rd = req.getRequestDispatcher("ViewTrains.html"); rd.include(req, res); pw.println("
Running Trains
"); @@ -30,31 +39,27 @@ protected void doGet(HttpServletRequest req,HttpServletResponse res) throws IOEx String fromStn; String toStn; do { - trainNo = rs.getLong("tr_no"); - fromStn = rs.getString("from_stn"); - toStn = rs.getString("to_stn"); - pw.println("" - + " " - + "" - + ""+rs.getString("tr_name")+"" - + ""+trainNo+"" - + ""+rs.getString("from_Stn")+"" - + ""+rs.getString("to_Stn")+"" - + ""+rs.getLong("available")+"" - + ""+rs.getLong("fare")+" RS"); - }while(rs.next()); + trainNo = rs.getLong("tr_no"); + fromStn = rs.getString("from_stn"); + toStn = rs.getString("to_stn"); + pw.println("" + " " + "" + "" + rs.getString("tr_name") + "" + + "" + trainNo + "" + "" + rs.getString("from_Stn") + "" + "" + + rs.getString("to_Stn") + "" + "" + rs.getLong("seats") + "" + + "" + rs.getDouble("fare") + " RS"); + } while (rs.next()); pw.println("

"); - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("ViewTrains.html"); rd.include(req, res); pw.println("
No Running Trains
"); } + } catch (Exception e) { + throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); + } - catch(Exception e) {} } - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("AdminLogin.html"); rd.include(req, res); pw.println("
Please Login first !
"); diff --git a/src/com/shashi/servlets/BookTrainByRef.java b/src/com/shashi/servlets/BookTrainByRef.java index 4ec603e..456b84a 100644 --- a/src/com/shashi/servlets/BookTrainByRef.java +++ b/src/com/shashi/servlets/BookTrainByRef.java @@ -1,46 +1,48 @@ package com.shashi.servlets; -import java.io.*; -import java.time.*; -import javax.servlet.*; -import javax.servlet.http.*; + +import java.io.IOException; +import java.io.PrintWriter; +import java.time.LocalDate; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + @SuppressWarnings("serial") -public class BookTrainByRef extends HttpServlet{ - public void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException - { +public class BookTrainByRef extends HttpServlet { + public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { PrintWriter pw = res.getWriter(); res.setContentType("text/html"); - Cookie ck[] =req.getCookies(); - if(ck!=null) { + Cookie ck[] = req.getCookies(); + if (ck != null) { String uName = ck[0].getValue(); - //String pWord = ck[1].getValue(); - - if(!uName.equals("")||uName != null ) - { - long trainNo =Long.parseLong(req.getParameter("trainNo")); + // String pWord = ck[1].getValue(); + + if (!uName.equals("") || uName != null) { + long trainNo = Long.parseLong(req.getParameter("trainNo")); int seat = 1; String fromStn = req.getParameter("fromStn"); String toStn = req.getParameter("toStn"); RequestDispatcher rd = req.getRequestDispatcher("UserViewTrains.html"); rd.include(req, res); pw.println("
Your Ticket Booking Information
"); - pw.println("
" - + "" - + "" - + "" - + "" - + "" - + "" + pw.println("
" + "
USER ID:"+uName+"Train NO:"+trainNo+"
From Station:"+fromStn+"To Station :"+toStn+"
Journey Date:" - + "" - + "" - + "No of Seats:
" + + "" + "" + "" + + "" + "" + "
USER ID:" + uName + "Train NO:" + trainNo + + "
From Station:" + fromStn + "To Station :" + toStn + "
Journey Date:" + + "" + + "" + + "No of Seats:
" + "
" + ""); } - } - else { - RequestDispatcher rd =req.getRequestDispatcher("UserLogin.html"); + } else { +// RequestDispatcher rd = req.getRequestDispatcher("UserLogin.html"); pw.println("
Please Login First!
"); } } diff --git a/src/com/shashi/servlets/BookTrainFwd.java b/src/com/shashi/servlets/BookTrainFwd.java index 80c6663..f69941c 100644 --- a/src/com/shashi/servlets/BookTrainFwd.java +++ b/src/com/shashi/servlets/BookTrainFwd.java @@ -1,23 +1,28 @@ package com.shashi.servlets; -import java.io.*; -import javax.servlet.*; -import javax.servlet.http.*; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + @SuppressWarnings("serial") -public class BookTrainFwd extends HttpServlet{ - public void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException - { +public class BookTrainFwd extends HttpServlet { + public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); - Cookie ck[] =req.getCookies(); - if(ck!=null) { + Cookie ck[] = req.getCookies(); + if (ck != null) { String uName = ck[0].getValue(); - //String pWord = ck[1].getValue(); - if(!uName.equals("")|| uName != null) - { - RequestDispatcher rd =req.getRequestDispatcher("BookTrains.html"); + // String pWord = ck[1].getValue(); + if (!uName.equals("") || uName != null) { + RequestDispatcher rd = req.getRequestDispatcher("BookTrains.html"); rd.forward(req, res); } - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("UserLogin.html"); PrintWriter pw = res.getWriter(); pw.println("
Please Login First !
"); diff --git a/src/com/shashi/servlets/BookTrains.java b/src/com/shashi/servlets/BookTrains.java index 5d6a5ee..e14e5ea 100644 --- a/src/com/shashi/servlets/BookTrains.java +++ b/src/com/shashi/servlets/BookTrains.java @@ -1,66 +1,72 @@ package com.shashi.servlets; -import java.io.*; -import java.sql.*; -import javax.servlet.*; -import javax.servlet.http.*; -import com.shashi.utility.DBConnection; +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.shashi.beans.TrainException; +import com.shashi.utility.DBUtil; + @SuppressWarnings("serial") -public class BookTrains extends HttpServlet{ - public void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException - { +public class BookTrains extends HttpServlet { + public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { PrintWriter pw = res.getWriter(); res.setContentType("text/html"); - Cookie ck[] =req.getCookies(); - if(ck!=null) { + Cookie ck[] = req.getCookies(); + if (ck != null) { String uName = ck[0].getValue(); - //String pWord = ck[1].getValue(); + // String pWord = ck[1].getValue(); RequestDispatcher rd = req.getRequestDispatcher("BookTrains.html"); rd.include(req, res); - if(!uName.equals("")||uName != null ) - { - long seat =Long.parseLong(req.getParameter("seats")); - long trainNo =Long.parseLong(req.getParameter("trainnumber")); + if (!uName.equals("") || uName != null) { + long seat = Long.parseLong(req.getParameter("seats")); + long trainNo = Long.parseLong(req.getParameter("trainnumber")); try { - Connection con = DBConnection.getCon(); - PreparedStatement ps = con.prepareStatement("Select * from train6 where tr_no = ?"); + Connection con = DBUtil.getCon(); + PreparedStatement ps = con.prepareStatement("Select * from train where tr_no = ?"); ps.setLong(1, trainNo); ResultSet rs = ps.executeQuery(); - if(rs.next()) - { - long avail =rs.getLong("available"); - if(seat>avail) { - pw.println("
Only "+avail+" Seats are Available in this Train!
"); - - } - else if(seat<=avail) { + if (rs.next()) { + long avail = rs.getLong("seats"); + if (seat > avail) { + pw.println("
Only " + avail + + " Seats are Available in this Train!
"); + + } else if (seat <= avail) { avail = avail - seat; - PreparedStatement ps1 = con.prepareStatement("update train6 set available=? where tr_no=?"); + PreparedStatement ps1 = con.prepareStatement("update train set seats=? where tr_no=?"); ps1.setLong(1, avail); ps1.setLong(2, trainNo); - int k= ps1.executeUpdate(); - if(k==1) - { - pw.println("
"+seat+" Seats Booked Successfully!
"); - - - } - else { - pw.println("
Transaction Declined. Try Again !
"); - + int k = ps1.executeUpdate(); + if (k == 1) { + pw.println("
" + seat + + " Seats Booked Successfully!
"); + + } else { + pw.println( + "
Transaction Declined. Try Again !
"); + } } - } - else { + } else { pw.println("
Invalid Train Number !
"); - + } - + + } catch (Exception e) { + throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); } - catch(Exception e) {} } - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("UserLogin.html"); pw.println("
Please Login First !
"); rd.include(req, res); diff --git a/src/com/shashi/servlets/ChangeUserPassword.java b/src/com/shashi/servlets/ChangeUserPassword.java index dcbb510..45f4b10 100644 --- a/src/com/shashi/servlets/ChangeUserPassword.java +++ b/src/com/shashi/servlets/ChangeUserPassword.java @@ -1,48 +1,47 @@ package com.shashi.servlets; -import java.io.*; -import javax.servlet.*; -import javax.servlet.http.*; -import com.shashi.beans.UserBean; +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +//import com.shashi.beans.UserBean; + @SuppressWarnings("serial") -public class ChangeUserPassword extends HttpServlet{ - protected void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException - { +public class ChangeUserPassword extends HttpServlet { + protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); PrintWriter pw = res.getWriter(); Cookie ck[] = req.getCookies(); - if(ck!=null) { + if (ck != null) { String uName = ck[0].getValue(); - String pWord = ck[1].getValue(); - if(!uName.equals("")||uName!=null) { - - ServletContext sct = req.getServletContext(); - UserBean ub = (UserBean)sct.getAttribute("ubean"); - RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); - rd.include(req, res); - pw.println("
" + - " " + - " Hello "+uName+" ! Welcome to our new NITRTC Website" + - " " + - "
"); - pw.println(""); - pw.println("
Password Change
"); - pw.println("
" - + "" - + "" - + "" - + "" - + "" - + "
User Name :
Old Password :
New Password :
" - + "
"); - - +// String pWord = ck[1].getValue(); + if (!uName.equals("") || uName != null) { + +// ServletContext sct = req.getServletContext(); +// UserBean ub = (UserBean) sct.getAttribute("ubean"); + RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); + rd.include(req, res); + pw.println("
" + " " + " Hello " + uName + + " ! Welcome to our new NITRTC Website" + " " + "
"); + pw.println(""); + pw.println("
Password Change
"); + pw.println("
" + "" + + "" + + "" + + "" + + "" + + "
User Name :
Old Password :
New Password :
" + "
"); + } - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("UserLogin.html"); rd.include(req, res); pw.println("
Please Login first !
"); diff --git a/src/com/shashi/servlets/ChangeUserPwd.java b/src/com/shashi/servlets/ChangeUserPwd.java index ff5c52b..62a2875 100644 --- a/src/com/shashi/servlets/ChangeUserPwd.java +++ b/src/com/shashi/servlets/ChangeUserPwd.java @@ -1,90 +1,94 @@ package com.shashi.servlets; -import java.io.*; -import javax.servlet.*; -import java.sql.*; -import javax.servlet.http.*; -import com.shashi.beans.UserBean; -import com.shashi.utility.DBConnection; +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; + +import javax.servlet.RequestDispatcher; +//import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.shashi.beans.TrainException; +import com.shashi.utility.DBUtil; + @SuppressWarnings("serial") -public class ChangeUserPwd extends HttpServlet{ - protected void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException - { +public class ChangeUserPwd extends HttpServlet { + protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); PrintWriter pw = res.getWriter(); Cookie ck[] = req.getCookies(); - if(ck!=null) { + if (ck != null) { String uName = ck[0].getValue(); String pWord = ck[1].getValue(); - if(!uName.equals("")||uName!=null) { - ServletContext sct = req.getServletContext(); - UserBean ub = (UserBean)sct.getAttribute("ubean"); + if (!uName.equals("") || uName != null) { +// ServletContext sct = req.getServletContext(); +// UserBean ub = (UserBean) sct.getAttribute("ubean"); try { - String u_Name = req.getParameter("username"); - String oldPWord = (String)req.getParameter("oldpassword"); - String newPWord = req.getParameter("newpassword"); - if(uName.equals(u_Name)) - { - if(pWord.equals(oldPWord)) - { - Connection con = DBConnection.getCon(); - PreparedStatement ps = con.prepareStatement("update register set pword=? where uname=? and pword=?"); - ps.setString(1, newPWord); - ps.setString(2,uName); - ps.setString(3, pWord); - int k= ps.executeUpdate(); - if(k==1) { - RequestDispatcher rd = req.getRequestDispatcher("UserLogin.html"); - rd.include(req, res); - - Cookie ck1 = new Cookie("ckname",""); - ck1.setMaxAge(0); - res.addCookie(ck1); - Cookie ck2 = new Cookie("ckpwd",""); - ck2.setMaxAge(0); - res.addCookie(ck2); - pw.println("
Your Username and Password has Been Updated Successfully
Please Login Again !
"); - } - else { + String u_Name = req.getParameter("username"); + String oldPWord = (String) req.getParameter("oldpassword"); + String newPWord = req.getParameter("newpassword"); + if (uName.equals(u_Name)) { + if (pWord.equals(oldPWord)) { + Connection con = DBUtil.getCon(); + PreparedStatement ps = con + .prepareStatement("update customer set pword=? where mailid=? and pword=?"); + ps.setString(1, newPWord); + ps.setString(2, uName); + ps.setString(3, pWord); + int k = ps.executeUpdate(); + if (k == 1) { + RequestDispatcher rd = req.getRequestDispatcher("UserLogin.html"); + rd.include(req, res); + + Cookie ck1 = new Cookie("ckname", ""); + ck1.setMaxAge(0); + res.addCookie(ck1); + Cookie ck2 = new Cookie("ckpwd", ""); + ck2.setMaxAge(0); + res.addCookie(ck2); + pw.println( + "
Your Username and Password has Been Updated Successfully
Please Login Again !
"); + } else { + RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); + rd.include(req, res); + pw.println("
" + " " + " Hello " + uName + + " ! Welcome to our new NITRTC Website" + " " + "
"); + pw.println( + ""); + pw.println("
Invalid Username and Old Password !
"); + } + } else { RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); rd.include(req, res); - pw.println("
" + - " " + - " Hello "+uName+" ! Welcome to our new NITRTC Website" + - " " + - "
"); - pw.println(""); - pw.println("
Invalid Username and Old Password !
"); + pw.println( + ""); + pw.println("
Wrong Old PassWord!
"); } - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); rd.include(req, res); pw.println(""); - pw.println("
Wrong Old PassWord!
"); - } - } - else { - RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); - rd.include(req, res); - pw.println(""); - pw.println("
Invalid UserName
"); - } - + + "Change Password" + ""); + pw.println("
Invalid UserName
"); + } + + } catch (Exception e) { + throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); } - catch(Exception e) {} } - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("UserLogin.html"); rd.include(req, res); pw.println("
Please Login first !
"); diff --git a/src/com/shashi/servlets/EditUserProfile.java b/src/com/shashi/servlets/EditUserProfile.java index 1f1fa5f..21cc689 100644 --- a/src/com/shashi/servlets/EditUserProfile.java +++ b/src/com/shashi/servlets/EditUserProfile.java @@ -1,51 +1,54 @@ package com.shashi.servlets; -import java.io.*; -import javax.servlet.*; -import javax.servlet.http.*; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import com.shashi.beans.UserBean; + @SuppressWarnings("serial") -public class EditUserProfile extends HttpServlet{ - protected void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException - { +public class EditUserProfile extends HttpServlet { + protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); PrintWriter pw = res.getWriter(); Cookie ck[] = req.getCookies(); - if(ck!=null) { + if (ck != null) { String uName = ck[0].getValue(); - String pWord = ck[1].getValue(); - if(!uName.equals("")||uName!=null) { - - ServletContext sct = req.getServletContext(); - UserBean ub = (UserBean)sct.getAttribute("ubean"); - RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); - rd.include(req, res); - pw.println("
" + - " " + - " Hello "+uName+" ! Welcome to our new NITRTC Website" + - " " + - "
"); - pw.println(""); - pw.println("
Profile Update
"); - pw.println("
" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "
User Name :
First Name :
Last Name :
Address :
Phone No:
Mail Id :
" - + "
"); - - +// String pWord = ck[1].getValue(); + if (!uName.equals("") || uName != null) { + + ServletContext sct = req.getServletContext(); + UserBean ub = (UserBean) sct.getAttribute("ubean"); + RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); + rd.include(req, res); + pw.println("
" + " " + " Hello " + uName + + " ! Welcome to our new NITRTC Website" + " " + "
"); + pw.println(""); + pw.println("
Profile Update
"); + pw.println("
" + "" + + "" + "" + + "" + "" + + "" + "" + + "" + + "
User Name :
First Name :
Last Name :
Address :
Phone No:
" + "
"); + } - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("UserLogin.html"); rd.include(req, res); pw.println("
Please Login first !
"); diff --git a/src/com/shashi/servlets/ErrorHandlerServlet.java b/src/com/shashi/servlets/ErrorHandlerServlet.java new file mode 100644 index 0000000..ece8094 --- /dev/null +++ b/src/com/shashi/servlets/ErrorHandlerServlet.java @@ -0,0 +1,71 @@ +package com.shashi.servlets; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Optional; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.shashi.beans.TrainException; +import com.shashi.constant.ResponseCode; + +public class ErrorHandlerServlet extends HttpServlet { + + /** + * + */ + private static final long serialVersionUID = 1L; + + public void service(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { + PrintWriter pw = res.getWriter(); + res.setContentType("text/html"); + + // Fetch the exceptions + Throwable throwable = (Throwable) req.getAttribute("javax.servlet.error.exception"); + Integer statusCode = (Integer) req.getAttribute("javax.servlet.error.status_code"); + String servletName = (String) req.getAttribute("javax.servlet.error.servlet_name"); + String requestUri = (String) req.getAttribute("javax.servlet.error.request_uri"); + String errorMessage = ResponseCode.INTERNAL_SERVER_ERROR.getMessage(); + String errorCode = ResponseCode.INTERNAL_SERVER_ERROR.name(); + + if (statusCode == null) + statusCode = 0; + Optional errorCodes = ResponseCode.getMessageByStatusCode(statusCode); + if (errorCodes.isPresent()) { + errorMessage = errorCodes.get().getMessage(); + errorCode = errorCodes.get().name(); + } + + if (throwable != null && throwable instanceof TrainException) { + TrainException trainException = (TrainException) throwable; + if (trainException != null) { + errorMessage = trainException.getMessage(); + statusCode = trainException.getStatusCode(); + errorCode = trainException.getErrorCode(); + trainException.printStackTrace(); + } + } else if (throwable != null) { + errorMessage = throwable.getMessage(); + errorCode = throwable.getLocalizedMessage(); + } + + System.out.println("======ERROR TRIGGERED========"); + System.out.println("Servlet Name: " + servletName); + System.out.println("Request URI: " + requestUri); + System.out.println("Status Code: " + statusCode); + System.out.println("Error Code: " + errorCode); + System.out.println("Error Message: " + errorMessage); + System.out.println("============================="); + + RequestDispatcher rd = req.getRequestDispatcher("error.html"); + rd.include(req, res); + pw.println("
\r\n" + "

" + + errorCode + "


\r\n" + "

" + errorMessage + "

\r\n" + "
"); + + } + +} diff --git a/src/com/shashi/servlets/FareEnq.java b/src/com/shashi/servlets/FareEnq.java index 0eae4e2..8919d7a 100644 --- a/src/com/shashi/servlets/FareEnq.java +++ b/src/com/shashi/servlets/FareEnq.java @@ -1,61 +1,67 @@ package com.shashi.servlets; -import java.io.*; -import javax.servlet.*; -import javax.servlet.http.*; -import com.shashi.utility.DBConnection; +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.shashi.beans.TrainException; +import com.shashi.utility.DBUtil; -import java.sql.*; @SuppressWarnings("serial") -public class FareEnq extends HttpServlet{ - protected void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException - { +public class FareEnq extends HttpServlet { + protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); PrintWriter pw = res.getWriter(); Cookie ck[] = req.getCookies(); - if(ck!=null) { + if (ck != null) { String uName = ck[0].getValue(); - String pWord = ck[1].getValue(); - if(!uName.equals("")||uName!=null) { +// String pWord = ck[1].getValue(); + if (!uName.equals("") || uName != null) { try { - Connection con = DBConnection.getCon(); - PreparedStatement ps = con.prepareStatement("Select * from train6 where from_stn=? and to_stn=?"); - ps.setString(1,req.getParameter("fromstation")); - ps.setString(2, req.getParameter("tostation")); + Connection con = DBUtil.getCon(); + PreparedStatement ps = con.prepareStatement("Select * from train where from_stn LIKE ? and to_stn LIKE ?"); + ps.setString(1, "%" + req.getParameter("fromstation").toUpperCase() + "%"); + ps.setString(2, "%" + req.getParameter("tostation").toUpperCase() + "%"); ResultSet rs = ps.executeQuery(); - if(rs.next()) - { + if (rs.next()) { RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); rd.include(req, res); - pw.println("
" + - " " + - " Hello "+uName+" ! Welcome to our new NITRTC Website" + - " " + - "
"); - pw.println("
Fare for Trains BetWeen Station "+req.getParameter("fromstation")+" and "+req.getParameter("tostation")+" is RS "+rs.getLong("fare")+"
"); + pw.println("
" + " " + " Hello " + uName + + " ! Welcome to our new NITRTC Website" + " " + "
"); + pw.println("
Fare for Trains BetWeen Station " + + req.getParameter("fromstation") + " and " + req.getParameter("tostation") + + " is RS " + rs.getLong("fare") + "
"); pw.println("
" + ""); do { - pw.println("" - + "" - + "" - + "" - + "" - + "" - + ""); - }while(rs.next()); + pw.println("" + "" + "" + "" + + "" + "" + ""); + } while (rs.next()); pw.println("
Train NameTrain NoFrom StnTo StnSeatsFare (INR)
"+rs.getString("tr_name")+""+rs.getLong("tr_no")+""+rs.getString("from_Stn")+""+rs.getString("to_Stn")+""+rs.getLong("available")+""+rs.getLong("fare")+" RS
" + rs.getString("tr_name") + "" + + rs.getLong("tr_no") + "" + rs.getString("from_Stn") + "" + rs.getString("to_Stn") + "" + rs.getLong("seats") + + "" + rs.getLong("fare") + " RS
"); - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("TrainBwStn.html"); rd.include(req, res); - pw.println("
There are no trains Between"+req.getParameter("fromstation")+" and "+req.getParameter("tostation")+"
"); } + pw.println("
There are no trains Between" + + req.getParameter("fromstation") + " and " + req.getParameter("tostation") + + "
"); + } + } catch (Exception e) { + throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); } - catch(Exception e) {} - + } - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("UserLogin.html"); rd.include(req, res); pw.println("
Please Login first !
"); diff --git a/src/com/shashi/servlets/FareEnqFwd.java b/src/com/shashi/servlets/FareEnqFwd.java index 51f51fe..0867067 100644 --- a/src/com/shashi/servlets/FareEnqFwd.java +++ b/src/com/shashi/servlets/FareEnqFwd.java @@ -1,22 +1,28 @@ package com.shashi.servlets; -import java.io.*; -import javax.servlet.*; -import javax.servlet.http.*; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + @SuppressWarnings("serial") -public class FareEnqFwd extends HttpServlet{ - protected void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException - { +public class FareEnqFwd extends HttpServlet { + protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); PrintWriter pw = res.getWriter(); Cookie ck[] = req.getCookies(); - if(ck!=null) { + if (ck != null) { String uName = ck[0].getValue(); - if(!uName.equals("")||uName!=null) { + if (!uName.equals("") || uName != null) { RequestDispatcher rd = req.getRequestDispatcher("Fare.html"); rd.forward(req, res); } - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("UserLogin.html"); rd.include(req, res); pw.println("
Please Login first !
"); diff --git a/src/com/shashi/servlets/TrainBwStn.java b/src/com/shashi/servlets/TrainBwStn.java index 37332ab..c5b0ecc 100644 --- a/src/com/shashi/servlets/TrainBwStn.java +++ b/src/com/shashi/servlets/TrainBwStn.java @@ -1,61 +1,67 @@ package com.shashi.servlets; -import java.io.*; -import javax.servlet.*; -import javax.servlet.http.*; -import com.shashi.utility.DBConnection; +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.shashi.beans.TrainException; +import com.shashi.utility.DBUtil; -import java.sql.*; @SuppressWarnings("serial") -public class TrainBwStn extends HttpServlet{ - protected void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException - { +public class TrainBwStn extends HttpServlet { + protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); PrintWriter pw = res.getWriter(); Cookie ck[] = req.getCookies(); - if(ck!=null) { + if (ck != null) { String uName = ck[0].getValue(); - String pWord = ck[1].getValue(); - if(!uName.equals("")||uName!=null) { +// String pWord = ck[1].getValue(); + if (!uName.equals("") || uName != null) { try { - Connection con = DBConnection.getCon(); - PreparedStatement ps = con.prepareStatement("Select * from train6 where from_stn=? and to_stn=?"); - ps.setString(1,req.getParameter("fromstation")); - ps.setString(2, req.getParameter("tostation")); + Connection con = DBUtil.getCon(); + PreparedStatement ps = con.prepareStatement("Select * from train where from_stn LIKE UPPER(?) and to_stn LIKE UPPER(?)"); + ps.setString(1, "%" + req.getParameter("fromstation") + "%"); + ps.setString(2, "%" + req.getParameter("tostation") + "%"); ResultSet rs = ps.executeQuery(); - if(rs.next()) - { + if (rs.next()) { RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); rd.include(req, res); - pw.println("
" + - " " + - " Hello "+uName+" ! Welcome to our new NITRTC Website" + - " " + - "
"); - pw.println("
Trains BetWeen Station "+req.getParameter("fromstation")+" and "+req.getParameter("tostation")+"
"); + pw.println("
" + " " + " Hello " + uName + + " ! Welcome to our new NITRTC Website" + " " + "
"); + pw.println("
Trains BetWeen Station " + + req.getParameter("fromstation") + " and " + req.getParameter("tostation") + + "
"); pw.println("
" + ""); do { - pw.println("" - + "" - + "" - + "" - + "" - + "" - + ""); - }while(rs.next()); + pw.println("" + "" + "" + "" + + "" + "" + ""); + } while (rs.next()); pw.println("
Train NameTrain NoFrom StnTo StnSeatsFare (INR)
"+rs.getString("tr_name")+""+rs.getLong("tr_no")+""+rs.getString("from_Stn")+""+rs.getString("to_Stn")+""+rs.getLong("available")+""+rs.getLong("fare")+" RS
" + rs.getString("tr_name") + "" + + rs.getLong("tr_no") + "" + rs.getString("from_Stn") + "" + rs.getString("to_Stn") + "" + rs.getLong("seats") + + "" + rs.getLong("fare") + " RS
"); - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("TrainBwStn.html"); rd.include(req, res); - pw.println("
There are no trains Between "+req.getParameter("fromstation")+" and "+req.getParameter("tostation")+"
"); } + pw.println("
There are no trains Between " + + req.getParameter("fromstation") + " and " + req.getParameter("tostation") + + "
"); + } + } catch (Exception e) { + throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); } - catch(Exception e) {} - + } - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("UserLogin.html"); rd.include(req, res); pw.println("
Please Login first !
"); diff --git a/src/com/shashi/servlets/TrainBwStnFwd.java b/src/com/shashi/servlets/TrainBwStnFwd.java index 32775af..fb0baf2 100644 --- a/src/com/shashi/servlets/TrainBwStnFwd.java +++ b/src/com/shashi/servlets/TrainBwStnFwd.java @@ -1,22 +1,28 @@ package com.shashi.servlets; -import java.io.*; -import javax.servlet.*; -import javax.servlet.http.*; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + @SuppressWarnings("serial") -public class TrainBwStnFwd extends HttpServlet{ - protected void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException - { +public class TrainBwStnFwd extends HttpServlet { + protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); PrintWriter pw = res.getWriter(); Cookie ck[] = req.getCookies(); - if(ck!=null) { + if (ck != null) { String uName = ck[0].getValue(); - if(!uName.equals("")||uName!=null) { + if (!uName.equals("") || uName != null) { RequestDispatcher rd = req.getRequestDispatcher("TrainBwStn.html"); rd.forward(req, res); } - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("UserLogin.html"); rd.include(req, res); pw.println("
Please Login first !
"); diff --git a/src/com/shashi/servlets/UpdateTrainSchedule.java b/src/com/shashi/servlets/UpdateTrainSchedule.java index a089543..10d75ea 100644 --- a/src/com/shashi/servlets/UpdateTrainSchedule.java +++ b/src/com/shashi/servlets/UpdateTrainSchedule.java @@ -1,48 +1,57 @@ package com.shashi.servlets; -import java.io.*; -import javax.servlet.*; -import javax.servlet.http.*; -import com.shashi.utility.DBConnection; +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.shashi.beans.TrainException; +import com.shashi.utility.DBUtil; -import java.sql.*; @SuppressWarnings("serial") -public class UpdateTrainSchedule extends HttpServlet{ - protected void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException - { +public class UpdateTrainSchedule extends HttpServlet { + protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); PrintWriter pw = res.getWriter(); Cookie ck[] = req.getCookies(); - if(ck!=null) { + if (ck != null) { String uName = ck[0].getValue(); - String pWord = ck[1].getValue(); - if(!uName.equals("")||uName!=null) { +// String pWord = ck[1].getValue(); + if (!uName.equals("") || uName != null) { try { - Connection con = DBConnection.getCon(); - PreparedStatement ps = con.prepareStatement("update train6 set tr_no=?,tr_name=?,from_stn=?,to_stn=?,available=?,fare=? where tr_no=?"); + Connection con = DBUtil.getCon(); + PreparedStatement ps = con.prepareStatement( + "update train set tr_no=?,tr_name=?,from_stn=?,to_stn=?,seats=?,fare=? where tr_no=?"); ps.setLong(1, Long.parseLong(req.getParameter("trainno"))); - ps.setString(2,req.getParameter("trainname")); + ps.setString(2, req.getParameter("trainname")); ps.setString(3, req.getParameter("fromstation")); ps.setString(4, req.getParameter("tostation")); ps.setLong(5, Long.parseLong(req.getParameter("available"))); - ps.setLong(6,Long.parseLong(req.getParameter("fare"))); + ps.setLong(6, Long.parseLong(req.getParameter("fare"))); ps.setLong(7, Long.parseLong(req.getParameter("trainno"))); ResultSet rs = ps.executeQuery(); - if(rs.next()) { + if (rs.next()) { RequestDispatcher rd = req.getRequestDispatcher("AdminUpdateTrain.html"); rd.include(req, res); pw.println("
Train Updated Successfully!
"); - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("AdminUpdateTrain.html"); rd.include(req, res); pw.println("
Error in filling the train Detail
"); } + } catch (Exception e) { + throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); } - catch(Exception e) {} } - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("AdminLogin.html"); rd.include(req, res); pw.println("
Please Login first !
"); diff --git a/src/com/shashi/servlets/UpdateUserProfile.java b/src/com/shashi/servlets/UpdateUserProfile.java index 5938ca8..2978420 100644 --- a/src/com/shashi/servlets/UpdateUserProfile.java +++ b/src/com/shashi/servlets/UpdateUserProfile.java @@ -1,24 +1,34 @@ package com.shashi.servlets; -import java.io.*; -import javax.servlet.*; -import java.sql.*; -import javax.servlet.http.*; +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.shashi.beans.TrainException; import com.shashi.beans.UserBean; -import com.shashi.utility.DBConnection; +import com.shashi.utility.DBUtil; + @SuppressWarnings("serial") -public class UpdateUserProfile extends HttpServlet{ - protected void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException - { +public class UpdateUserProfile extends HttpServlet { + protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); PrintWriter pw = res.getWriter(); Cookie ck[] = req.getCookies(); - if(ck!=null) { + if (ck != null) { String uName = ck[0].getValue(); - String pWord = ck[1].getValue(); - if(!uName.equals("")||uName!=null) { + //String pWord = ck[1].getValue(); + if (!uName.equals("") || uName != null) { ServletContext sct = req.getServletContext(); - UserBean ub = (UserBean)sct.getAttribute("ubean"); + UserBean ub = (UserBean) sct.getAttribute("ubean"); String u_Name = req.getParameter("username"); String fName = req.getParameter("firstname"); String lName = req.getParameter("lastname"); @@ -26,51 +36,47 @@ protected void doPost(HttpServletRequest req,HttpServletResponse res) throws IOE long phNo = Long.parseLong(req.getParameter("phone")); String mailId = req.getParameter("mail"); try { - Connection con = DBConnection.getCon();//Get photo from userphoto sql table created - PreparedStatement ps = con.prepareStatement("update register set uname=?,fname=?,lname=?,addr=?,phno=?,mailid=? where uname=? and pword=?"); - ps.setString(1, u_Name); - ps.setString(2, fName); - ps.setString(3, lName); - ps.setString(4, addR); - ps.setLong(5, phNo); - ps.setString(6,mailId); - ps.setString(7, uName); - ps.setString(8, pWord); - int k= ps.executeUpdate(); - if(k==1) { - ub.setUName(u_Name); - ub.setLName(lName); - ub.setFName(fName); - ub.setMailId(mailId); - ub.setAddr(addR); - ub.setPhNo(phNo); - RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); - rd.include(req, res); - pw.println("
" + - " " + - " Hello "+uName+" ! Welcome to our new NITRTC Website" + - " " + - "
"); - pw.println(""); - pw.println("
Your Profile has Been Successfully Updated
"); - } - else { - RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); - rd.include(req, res); - pw.println(""); - pw.println("
Please Enter the valid Information
"); - } - } - catch(Exception e) {} + Connection con = DBUtil.getCon();// Get photo from userphoto sql table created + PreparedStatement ps = con.prepareStatement( + "update customer set fname=?,lname=?,addr=?,phno=? where mailid=?"); +// ps.setString(1, u_Name); + ps.setString(1, fName); + ps.setString(2, lName); + ps.setString(3, addR); + ps.setLong(4, phNo); + ps.setString(5, mailId); +// ps.setString(7, uName); + //ps.setString(6, pWord); + int k = ps.executeUpdate(); + if (k == 1) { +// ub.setUName(u_Name); + ub.setLName(lName); + ub.setFName(fName); + ub.setMailId(mailId); + ub.setAddr(addR); + ub.setPhNo(phNo); + RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); + rd.include(req, res); + pw.println("
" + " " + " Hello " + uName + + " ! Welcome to our new NITRTC Website" + " " + "
"); + pw.println(""); + pw.println("
Your Profile has Been Successfully Updated
"); + } else { + RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); + rd.include(req, res); + pw.println(""); + pw.println("
Please Enter the valid Information
"); + } + } catch (Exception e) { + throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); + } - } - else { + } + } else { RequestDispatcher rd = req.getRequestDispatcher("UserLogin.html"); rd.include(req, res); pw.println("
Please Login first !
"); diff --git a/src/com/shashi/servlets/UserAvailFwd.java b/src/com/shashi/servlets/UserAvailFwd.java index 3d7235d..a455b94 100644 --- a/src/com/shashi/servlets/UserAvailFwd.java +++ b/src/com/shashi/servlets/UserAvailFwd.java @@ -1,24 +1,30 @@ package com.shashi.servlets; -import java.io.*; -import javax.servlet.*; -import javax.servlet.http.*; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + @SuppressWarnings("serial") -public class UserAvailFwd extends HttpServlet{ - protected void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException - { +public class UserAvailFwd extends HttpServlet { + protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); PrintWriter pw = res.getWriter(); Cookie ck[] = req.getCookies(); - if(ck!=null) { + if (ck != null) { String uName = ck[0].getValue(); - String pWord = ck[1].getValue(); - if(!uName.equals("")||uName!=null) { +// String pWord = ck[1].getValue(); + if (!uName.equals("") || uName != null) { RequestDispatcher rd = req.getRequestDispatcher("Availability.html"); rd.forward(req, res); - + } - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("UserLogin.html"); rd.include(req, res); pw.println("
Please Login first !
"); diff --git a/src/com/shashi/servlets/UserAvailServlet.java b/src/com/shashi/servlets/UserAvailServlet.java index 2264a3c..6f5fb36 100644 --- a/src/com/shashi/servlets/UserAvailServlet.java +++ b/src/com/shashi/servlets/UserAvailServlet.java @@ -1,59 +1,64 @@ package com.shashi.servlets; -import java.io.*; -import javax.servlet.*; -import javax.servlet.http.*; -import com.shashi.utility.DBConnection; +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.shashi.beans.TrainException; +import com.shashi.utility.DBUtil; -import java.sql.*; @SuppressWarnings("serial") -public class UserAvailServlet extends HttpServlet{ - protected void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException - { +public class UserAvailServlet extends HttpServlet { + protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); PrintWriter pw = res.getWriter(); Cookie ck[] = req.getCookies(); - if(ck!=null) { + if (ck != null) { String uName = ck[0].getValue(); - String pWord = ck[1].getValue(); - if(!uName.equals("")||uName!=null) { +// String pWord = ck[1].getValue(); + if (!uName.equals("") || uName != null) { try { - Connection con = DBConnection.getCon(); - PreparedStatement ps = con.prepareStatement("Select * from train6 where tr_no=?"); - ps.setLong(1,Long.parseLong(req.getParameter("trainno"))); + Connection con = DBUtil.getCon(); + PreparedStatement ps = con.prepareStatement("Select * from train where tr_no=?"); + ps.setLong(1, Long.parseLong(req.getParameter("trainno"))); ResultSet rs = ps.executeQuery(); - if(rs.next()) { + if (rs.next()) { RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); rd.include(req, res); - pw.println("
" + - " " + - " Hello "+uName+" ! Welcome to our new NITRTC Website" + - " " + - "
"); - pw.println("
Available Seats are "+rs.getLong("available")+" Seats
"); - pw.println("
" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "
Train Name :"+rs.getString("tr_name")+"
Train Number :"+rs.getLong("tr_no")+"
From Station :"+rs.getString("from_Stn")+"
To Station :"+rs.getString("to_Stn")+"
Available Seats:"+rs.getLong("available")+"
Fare (INR) :"+rs.getLong("fare")+" RS
" - + "
"); - } - else { + pw.println("
" + " " + " Hello " + uName + + " ! Welcome to our new NITRTC Website" + " " + "
"); + pw.println("
Available Seats are " + + rs.getLong("seats") + " Seats
"); + pw.println("
" + "" + "" + + "" + + "" + "" + "" + "" + "
Train Name :" + + rs.getString("tr_name") + "
Train Number :" + rs.getLong("tr_no") + "
From Station :" + rs.getString("from_Stn") + + "
To Station :" + rs.getString("to_Stn") + + "
Available Seats:" + + rs.getLong("seats") + "
Fare (INR) :" + + rs.getLong("fare") + " RS
" + "
"); + } else { RequestDispatcher rd = req.getRequestDispatcher("Availability.html"); rd.include(req, res); - - pw.println("
Train No."+req.getParameter("trainno")+" is Not Available !
"); + + pw.println("
Train No." + req.getParameter("trainno") + + " is Not Available !
"); } + } catch (Exception e) { + throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); } - catch(Exception e) {} - + } - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("UserLogin.html"); rd.include(req, res); pw.println("
Please Login first !
"); diff --git a/src/com/shashi/servlets/UserHome.java b/src/com/shashi/servlets/UserHome.java index 10ff275..b034a64 100644 --- a/src/com/shashi/servlets/UserHome.java +++ b/src/com/shashi/servlets/UserHome.java @@ -1,32 +1,35 @@ package com.shashi.servlets; -import java.io.*; -import javax.servlet.*; -import javax.servlet.http.*; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + @SuppressWarnings("serial") -public class UserHome extends HttpServlet{ - protected void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException - { +public class UserHome extends HttpServlet { + protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); PrintWriter pw = res.getWriter(); Cookie ck[] = req.getCookies(); - if(ck!=null) { + if (ck != null) { String uName = ck[0].getValue(); - if(!uName.equals("")||uName!=null) { + if (!uName.equals("") || uName != null) { RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); rd.include(req, res); - pw.println("
" + - " " + - " Hello "+uName+" ! Welcome to our new NITRTC Website" + - " " + - "
"); + pw.println("
" + " " + " Hello " + uName + + " ! Welcome to our new NITRTC Website" + " " + "
"); pw.println("
User Home
"); - pw.println("
Hello "+uName+" ! Good to See You here.
Here you can Check up the train " + pw.println("
Hello " + uName + + " ! Good to See You here.
Here you can Check up the train " + "details, train schedule, fare Enquiry and many more information.
Just go to the Side Menu Links and " - + "Explore the Advantages.

Thanks For Being Connected with us!" - + "
"); + + "Explore the Advantages.

Thanks For Being Connected with us!" + "
"); } - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("UserLogin.html"); rd.include(req, res); pw.println("
Please Login first !
"); diff --git a/src/com/shashi/servlets/UserLoginServlet.java b/src/com/shashi/servlets/UserLoginServlet.java index d599624..e135c54 100644 --- a/src/com/shashi/servlets/UserLoginServlet.java +++ b/src/com/shashi/servlets/UserLoginServlet.java @@ -1,83 +1,89 @@ package com.shashi.servlets; -import java.io.*; -import java.sql.*; -import javax.servlet.*; -import javax.servlet.http.*; +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.shashi.beans.TrainException; import com.shashi.beans.UserBean; -import com.shashi.utility.DBConnection; +import com.shashi.utility.DBUtil; + @SuppressWarnings("serial") -public class UserLoginServlet extends HttpServlet{ - protected void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException - { +public class UserLoginServlet extends HttpServlet { + protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { PrintWriter pw = res.getWriter(); res.setContentType("text/html"); String uName = req.getParameter("uname"); String pWord = req.getParameter("pword"); try { - Connection con = DBConnection.getCon(); - - PreparedStatement ps = con.prepareStatement("select * from register where uname=? and pword=?"); - + Connection con = DBUtil.getCon(); + + PreparedStatement ps = con.prepareStatement("select * from customer where mailid=? and pword=?"); + ps.setString(1, uName); ps.setString(2, pWord); ResultSet rs = ps.executeQuery(); - if(rs.next()) - { + if (rs.next()) { UserBean ub = new UserBean(); - ub.setUName(rs.getString("uname")); + ub.setMailId(rs.getString("mailid")); ub.setPWord(rs.getString("pword")); ub.setFName(rs.getString("fname")); ub.setLName(rs.getString("lname")); ub.setAddr(rs.getString("addr")); ub.setPhNo(Long.parseLong(rs.getString("phno"))); - ub.setMailId(rs.getString("mailid")); - - /* PreparedStatement ps2 = preparedStatement("select * from userphoto where uname=?"); - ps2.setString(1, uName); - ResultSet rs2 = ps2.executeQuery(); - if(rs2.next()) - { - ub.setPhoto(rs2.getBlob(2)); - } - */ - + + /* + * PreparedStatement ps2 = + * preparedStatement("select * from userphoto where uname=?"); ps2.setString(1, + * uName); ResultSet rs2 = ps2.executeQuery(); if(rs2.next()) { + * ub.setPhoto(rs2.getBlob(2)); } + */ + // Updating for Profile Photo of user - - Cookie ck1 = new Cookie("ckname",uName); + + Cookie ck1 = new Cookie("ckname", uName); res.addCookie(ck1); - Cookie ck2 = new Cookie("ckpwd",pWord); + Cookie ck2 = new Cookie("ckpwd", pWord); res.addCookie(ck2); ServletContext sct = req.getServletContext(); sct.setAttribute("ubean", ub); - RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); - rd.include(req, res); - pw.println("
Hello "+uName+" ! Welcome to our new NITRTC Website
"); - pw.println("
Hello "+uName+" ! Good to See You here.
Here you can Check up the train " - + "details and train schedule,fare Enquiry and many more information.
Just go to the Side Menu Links and " - + "Explore the Advantages.

Thanks For Being Connected with us!" - + "
"); - - PreparedStatement ps2 = preparedStatement("select * from userphoto where uname=?"); - ps2.setString(1, uName); - ResultSet rs2 = ps2.executeQuery(); - if(rs2.next()) - { - ub.setPhoto(rs2.getBlob(2)); - } - - } - else - { + RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); + rd.include(req, res); + pw.println("
Hello " + uName + + " ! Welcome to our new NITRTC Website
"); + pw.println("
Hello " + uName + + " ! Good to See You here.
Here you can Check up the train " + + "details and train schedule,fare Enquiry and many more information.
Just go to the Side Menu Links and " + + "Explore the Advantages.

Thanks For Being Connected with us!" + "
"); + +// PreparedStatement ps2 = preparedStatement("select * from userphoto where uname=?"); +// ps2.setString(1, uName); +// ResultSet rs2 = ps2.executeQuery(); +// if (rs2.next()) { +// ub.setPhoto(rs2.getBlob(2)); +// } + + } else { RequestDispatcher rd = req.getRequestDispatcher("UserLogin.html"); rd.include(req, res); - + pw.println("
Invalid Username Or Password !
"); } - + + } catch (Exception e) { + throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); } - catch(Exception e) {} } private PreparedStatement preparedStatement(String string) { diff --git a/src/com/shashi/servlets/UserLogoutServlet.java b/src/com/shashi/servlets/UserLogoutServlet.java index b8140a7..1975bb4 100644 --- a/src/com/shashi/servlets/UserLogoutServlet.java +++ b/src/com/shashi/servlets/UserLogoutServlet.java @@ -1,41 +1,48 @@ package com.shashi.servlets; -import java.io.*; -import javax.servlet.*; -import javax.servlet.http.*; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import com.shashi.beans.UserBean; + @SuppressWarnings("serial") -public class UserLogoutServlet extends HttpServlet{ - protected void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException - { +public class UserLogoutServlet extends HttpServlet { + protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter pw = res.getWriter(); Cookie ck[] = req.getCookies(); - if(ck!=null) { - - Cookie ck1 = new Cookie("ckname",""); + if (ck != null) { + + Cookie ck1 = new Cookie("ckname", ""); ck1.setMaxAge(0); res.addCookie(ck1); - Cookie ck2 = new Cookie("ckpwd",""); + Cookie ck2 = new Cookie("ckpwd", ""); ck2.setMaxAge(0); res.addCookie(ck2); ServletContext sct = req.getServletContext(); - UserBean ub = (UserBean)sct.getAttribute("ubean"); + UserBean ub = (UserBean) sct.getAttribute("ubean"); ub.setAddr(""); ub.setFName(""); ub.setLName(""); ub.setMailId(""); ub.setPhNo(0); ub.setPWord(""); - ub.setUName(""); +// ub.setUName(""); RequestDispatcher rd = req.getRequestDispatcher("UserLogin.html"); rd.include(req, res); pw.println("
You have been successfully logged out !
"); - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("UserLogin.html"); rd.include(req, res); - + pw.println("
You are Already Logged Out !
"); } } diff --git a/src/com/shashi/servlets/UserProfile.java b/src/com/shashi/servlets/UserProfile.java index ff2094f..e06521c 100644 --- a/src/com/shashi/servlets/UserProfile.java +++ b/src/com/shashi/servlets/UserProfile.java @@ -1,36 +1,38 @@ package com.shashi.servlets; -import java.io.*; -import javax.servlet.*; -import javax.servlet.http.*; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + @SuppressWarnings("serial") -public class UserProfile extends HttpServlet{ - protected void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException - { +public class UserProfile extends HttpServlet { + protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); PrintWriter pw = res.getWriter(); Cookie ck[] = req.getCookies(); - if(ck!=null) { + if (ck != null) { String uName = ck[0].getValue(); - String pWord = ck[1].getValue(); - if(!uName.equals("")||uName!=null) { +// String pWord = ck[1].getValue(); + if (!uName.equals("") || uName != null) { RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); rd.include(req, res); - pw.println("
" + - " " + - " Hello "+uName+" ! Welcome to our new NITRTC Website" + - " " + - "
"); + pw.println("
" + " " + " Hello " + uName + + " ! Welcome to our new NITRTC Website" + " " + "
"); pw.println(""); - pw.println("
Hey ! "+uName+",Welcome to NITRTC

Here You can Edit,View Your Profile and change your PassWord.
" - + "
Thanks For Being Connected With Us!" - + "
"); - + + "Change Password" + ""); + pw.println("
Hey ! " + uName + + ",Welcome to NITRTC

Here You can Edit,View Your Profile and change your PassWord.
" + + "
Thanks For Being Connected With Us!" + "
"); + } - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("UserLogin.html"); rd.include(req, res); pw.println("
Please Login first !
"); diff --git a/src/com/shashi/servlets/UserRegServlet.java b/src/com/shashi/servlets/UserRegServlet.java index ae247d3..613b5ee 100644 --- a/src/com/shashi/servlets/UserRegServlet.java +++ b/src/com/shashi/servlets/UserRegServlet.java @@ -1,50 +1,61 @@ package com.shashi.servlets; -import java.io.*; -import java.sql.*; -import javax.servlet.*; -import javax.servlet.http.*; - -import com.shashi.utility.DBConnection; -public class UserRegServlet extends HttpServlet{ - protected void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException - { + +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.shashi.beans.TrainException; +import com.shashi.utility.DBUtil; + +public class UserRegServlet extends HttpServlet { + /** + * + */ + private static final long serialVersionUID = 1L; + + protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); PrintWriter pw = res.getWriter(); try { - Connection con = DBConnection.getCon(); - PreparedStatement ps = con.prepareStatement("insert into register values(?,?,?,?,?,?,?)"); - - ps.setString(1, req.getParameter("uname")); + Connection con = DBUtil.getCon(); + PreparedStatement ps = con.prepareStatement("insert into customer values(?,?,?,?,?,?)"); + + ps.setString(1, req.getParameter("mailid")); ps.setString(2, req.getParameter("pword")); ps.setString(3, req.getParameter("firstname")); ps.setString(4, req.getParameter("lastname")); ps.setString(5, req.getParameter("address")); ps.setLong(6, Long.parseLong(req.getParameter("phoneno"))); - ps.setString(7, req.getParameter("mailid")); +// ps.setString(7, req.getParameter("mailid")); int k = ps.executeUpdate(); - if(k==1) { + if (k == 1) { RequestDispatcher rd = req.getRequestDispatcher("UserLogin.html"); rd.include(req, res); pw.println("
User Registered Successfully !
"); - - } - - /*PreparedStatement ps2 = con.prepareStatement("insert into userphoto values(?,?)"); - ps2.setString(1, req.getParameter("uname")); - Part filepart = req.getPart("userphoto"); - InputStream inputStream; - inputStream = filepart.getInputStream(); - ps2.setBlob(2, inputStream); - int l = ps2.executeUpdate(); - if(l==1) - { - pw.println("
And User Photo updated Successfully !
"); + } - else { - pw.println("
Unable to upload photo !
"); - }*/ + + /* + * PreparedStatement ps2 = + * con.prepareStatement("insert into userphoto values(?,?)"); ps2.setString(1, + * req.getParameter("uname")); Part filepart = req.getPart("userphoto"); + * InputStream inputStream; inputStream = filepart.getInputStream(); + * ps2.setBlob(2, inputStream); int l = ps2.executeUpdate(); if(l==1) { pw. + * println("
And User Photo updated Successfully !
" + * ); } else { pw. + * println("
Unable to upload photo !
" + * ); } + */ + } catch (Exception e) { + throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); } - catch(Exception e) {} } } diff --git a/src/com/shashi/servlets/UserSearchFwd.java b/src/com/shashi/servlets/UserSearchFwd.java index f470680..92b048d 100644 --- a/src/com/shashi/servlets/UserSearchFwd.java +++ b/src/com/shashi/servlets/UserSearchFwd.java @@ -1,23 +1,29 @@ package com.shashi.servlets; -import java.io.*; -import javax.servlet.*; -import javax.servlet.http.*; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + @SuppressWarnings("serial") -public class UserSearchFwd extends HttpServlet{ - protected void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException - { +public class UserSearchFwd extends HttpServlet { + protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); PrintWriter pw = res.getWriter(); Cookie ck[] = req.getCookies(); - if(ck!=null) { + if (ck != null) { String uName = ck[0].getValue(); - if(!uName.equals("")||uName!=null) { + if (!uName.equals("") || uName != null) { RequestDispatcher rd = req.getRequestDispatcher("SearchTrains.html"); rd.forward(req, res); } - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("UserLogin.html"); rd.include(req, res); pw.println("
Please Login first !
"); diff --git a/src/com/shashi/servlets/UserSearchTrain.java b/src/com/shashi/servlets/UserSearchTrain.java index 6e6a152..83265fb 100644 --- a/src/com/shashi/servlets/UserSearchTrain.java +++ b/src/com/shashi/servlets/UserSearchTrain.java @@ -1,58 +1,62 @@ package com.shashi.servlets; -import java.io.*; -import javax.servlet.*; -import javax.servlet.http.*; -import com.shashi.utility.DBConnection; +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.shashi.beans.TrainException; +import com.shashi.utility.DBUtil; -import java.sql.*; @SuppressWarnings("serial") -public class UserSearchTrain extends HttpServlet{ - protected void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException - { +public class UserSearchTrain extends HttpServlet { + protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); PrintWriter pw = res.getWriter(); Cookie ck[] = req.getCookies(); - if(ck!=null) { + if (ck != null) { String uName = ck[0].getValue(); - String pWord = ck[1].getValue(); - if(!uName.equals("")||uName!=null) { +// String pWord = ck[1].getValue(); + if (!uName.equals("") || uName != null) { try { - Connection con = DBConnection.getCon(); - PreparedStatement ps = con.prepareStatement("Select * from train6 where tr_no=?"); - ps.setLong(1,Long.parseLong(req.getParameter("trainnumber"))); + Connection con = DBUtil.getCon(); + PreparedStatement ps = con.prepareStatement("Select * from train where tr_no=?"); + ps.setLong(1, Long.parseLong(req.getParameter("trainnumber"))); ResultSet rs = ps.executeQuery(); - if(rs.next()) { + if (rs.next()) { RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); rd.include(req, res); - pw.println("
" + - " " + - " Hello "+uName+" ! Welcome to our new NITRTC Website" + - " " + - "
"); + pw.println("
" + " " + " Hello " + uName + + " ! Welcome to our new NITRTC Website" + " " + "
"); pw.println("
Searched Train Detail
"); - pw.println("
" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "
Train Name :"+rs.getString("tr_name")+"
Train Number :"+rs.getLong("tr_no")+"
From Station :"+rs.getString("from_Stn")+"
To Station :"+rs.getString("to_Stn")+"
Available Seats:"+rs.getLong("available")+"
Fare (INR) :"+rs.getLong("fare")+" RS
" - + "
"); - } - else { + pw.println("
" + "" + "" + + "" + + "" + "" + "" + "" + "
Train Name :" + + rs.getString("tr_name") + "
Train Number :" + rs.getLong("tr_no") + "
From Station :" + rs.getString("from_Stn") + + "
To Station :" + rs.getString("to_Stn") + + "
Available Seats:" + + rs.getLong("seats") + "
Fare (INR) :" + + rs.getLong("fare") + " RS
" + "
"); + } else { RequestDispatcher rd = req.getRequestDispatcher("SearchTrains.html"); rd.include(req, res); - pw.println("
Train No."+req.getParameter("trainnumber")+" is Not Available !
"); + pw.println("
Train No." + req.getParameter("trainnumber") + + " is Not Available !
"); } + } catch (Exception e) { + throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); } - catch(Exception e) {} - + } - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("UserLogin.html"); rd.include(req, res); pw.println("
Please Login first !
"); diff --git a/src/com/shashi/servlets/UserViewLinkGet.java b/src/com/shashi/servlets/UserViewLinkGet.java index 2b826e8..488609a 100644 --- a/src/com/shashi/servlets/UserViewLinkGet.java +++ b/src/com/shashi/servlets/UserViewLinkGet.java @@ -1,60 +1,65 @@ package com.shashi.servlets; -import java.io.*; -import javax.servlet.*; -import javax.servlet.http.*; -import com.shashi.utility.DBConnection; +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.shashi.beans.TrainException; +import com.shashi.utility.DBUtil; -import java.sql.*; @SuppressWarnings("serial") -public class UserViewLinkGet extends HttpServlet{ - protected void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException - { +public class UserViewLinkGet extends HttpServlet { + protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); PrintWriter pw = res.getWriter(); Cookie ck[] = req.getCookies(); - if(ck!=null) { + if (ck != null) { String uName = ck[0].getValue(); - String pWord = ck[1].getValue(); - if(!uName.equals("")||uName!=null) { +// String pWord = ck[1].getValue(); + if (!uName.equals("") || uName != null) { try { - Connection con = DBConnection.getCon(); - PreparedStatement ps = con.prepareStatement("Select * from train6 where tr_no=? and from_stn=? and to_stn=?"); - ps.setLong(1,Long.parseLong(req.getParameter("trainNo"))); + Connection con = DBUtil.getCon(); + PreparedStatement ps = con + .prepareStatement("Select * from train where tr_no=? and from_stn=UPPER(?) and to_stn=UPPER(?)"); + ps.setLong(1, Long.parseLong(req.getParameter("trainNo"))); ps.setString(2, req.getParameter("fromStn")); ps.setString(3, req.getParameter("toStn")); ResultSet rs = ps.executeQuery(); - if(rs.next()) { + if (rs.next()) { RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); rd.include(req, res); - pw.println("
" + - " " + - " Hello "+uName+" ! Welcome to our new NITRTC Website" + - " " + - "
"); + pw.println("
" + " " + " Hello " + uName + + " ! Welcome to our new NITRTC Website" + " " + "
"); pw.println("
Selected Train Detail
"); - pw.println("
" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "
Train Name :"+rs.getString("tr_name")+"
Train Number :"+rs.getLong("tr_no")+"
From Station :"+rs.getString("from_Stn")+"
To Station :"+rs.getString("to_Stn")+"
Available Seats:"+rs.getLong("available")+"
Fare (INR) :"+rs.getLong("fare")+" RS
" - + "
"); - } - else { + pw.println("
" + "" + "" + + "" + + "" + "" + "" + "" + "
Train Name :" + + rs.getString("tr_name") + "
Train Number :" + rs.getLong("tr_no") + "
From Station :" + rs.getString("from_Stn") + + "
To Station :" + rs.getString("to_Stn") + + "
Available Seats:" + + rs.getLong("SEATS") + "
Fare (INR) :" + + rs.getLong("fare") + " RS
" + "
"); + } else { RequestDispatcher rd = req.getRequestDispatcher("SearchTrains.html"); rd.include(req, res); - pw.println("
Train No."+req.getParameter("trainnumber")+" is Not Available !
"); + pw.println("
Train No." + req.getParameter("trainnumber") + + " is Not Available !
"); } + } catch (Exception e) { + throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); } - catch(Exception e) {} - + } - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("UserLogin.html"); rd.include(req, res); pw.println("
Please Login first !
"); diff --git a/src/com/shashi/servlets/UserViewTrainFwd.java b/src/com/shashi/servlets/UserViewTrainFwd.java index d891fc3..3c0d83b 100644 --- a/src/com/shashi/servlets/UserViewTrainFwd.java +++ b/src/com/shashi/servlets/UserViewTrainFwd.java @@ -1,33 +1,39 @@ package com.shashi.servlets; -import java.io.*; -import java.sql.*; -import javax.servlet.*; -import javax.servlet.http.*; -import com.shashi.utility.DBConnection; +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.shashi.beans.TrainException; +import com.shashi.utility.DBUtil; + @SuppressWarnings("serial") -public class UserViewTrainFwd extends HttpServlet{ - protected void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException - { +public class UserViewTrainFwd extends HttpServlet { + protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); PrintWriter pw = res.getWriter(); Cookie ck[] = req.getCookies(); - if(ck!=null) { + if (ck != null) { String uName = ck[0].getValue(); - if(!uName.equals("")||uName!=null) { + if (!uName.equals("") || uName != null) { try { - Connection con = DBConnection.getCon(); - PreparedStatement ps = con.prepareStatement("Select * from train6"); + Connection con = DBUtil.getCon(); + PreparedStatement ps = con.prepareStatement("Select * from train"); ResultSet rs = ps.executeQuery(); - if(rs.next()) - { + if (rs.next()) { RequestDispatcher rd = req.getRequestDispatcher("UserViewTrains.html"); rd.include(req, res); - pw.println("
" + - " " + - " Hello "+uName+" ! Welcome to our new NITRTC Website" + - " " + - "
"); + pw.println("
" + " " + " Hello " + uName + + " ! Welcome to our new NITRTC Website" + " " + "
"); pw.println("
Running Trains
"); pw.println("
" + ""); @@ -35,33 +41,27 @@ protected void doGet(HttpServletRequest req,HttpServletResponse res) throws IOEx String fromStn; String toStn; do { - trainNo = rs.getLong("tr_no"); - fromStn = rs.getString("from_stn"); - toStn = rs.getString("to_stn"); - pw.println("" - + " " - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - ); - }while(rs.next()); + trainNo = rs.getLong("tr_no"); + fromStn = rs.getString("from_stn"); + toStn = rs.getString("to_stn"); + pw.println("" + " " + "" + "" + + "" + "" + "" + + "" + "" + ""); + } while (rs.next()); pw.println("
Train NameTrain NumberFrom StationTo StationSeats AvailableFare (INR)Booking
"+rs.getString("tr_name")+""+trainNo+""+fromStn+""+toStn+""+rs.getLong("available")+""+rs.getLong("fare")+" RS
Book Now
" + rs.getString("tr_name") + "" + trainNo + "" + fromStn + "" + toStn + "" + rs.getLong("SEATS") + "" + rs.getLong("fare") + + " RS
Book Now
"); - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("UserViewTrains.html"); rd.include(req, res); pw.println("
No Running Trains
"); } + } catch (Exception e) { + throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); } - catch(Exception e) {} } - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("UserLogin.html"); rd.include(req, res); pw.println("
Please Login first !
"); diff --git a/src/com/shashi/servlets/ViewUserProfile.java b/src/com/shashi/servlets/ViewUserProfile.java index 313c030..6879c1a 100644 --- a/src/com/shashi/servlets/ViewUserProfile.java +++ b/src/com/shashi/servlets/ViewUserProfile.java @@ -1,53 +1,49 @@ package com.shashi.servlets; -import java.io.*; -import java.sql.*; -import javax.servlet.*; -import javax.servlet.http.*; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import com.shashi.beans.UserBean; + @SuppressWarnings("serial") -public class ViewUserProfile extends HttpServlet{ - protected void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException - { +public class ViewUserProfile extends HttpServlet { + protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); PrintWriter pw = res.getWriter(); Cookie ck[] = req.getCookies(); - if(ck!=null) { + if (ck != null) { String uName = ck[0].getValue(); - String pWord = ck[1].getValue(); - if(!uName.equals("")||uName!=null) { - - ServletContext sct = req.getServletContext(); - UserBean ub = (UserBean)sct.getAttribute("ubean"); - RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); - rd.include(req, res); - pw.println("
" + - " " + - " Hello "+uName+" ! Welcome to our new NITRTC Website" + - " " + - "
"); - pw.println(""); - pw.println("
Users Profile View
"); - pw.println("
" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "
Profile Photo :"+ub.getPhoto()+"
User Name :"+ub.getUName()+"
Password :"+ub.getPWord()+"
First Name :"+ub.getFName()+"
Last Name :"+ub.getLName()+"
Address :"+ub.getAddr()+"
Phone No:"+ub.getPhNo()+"
Mail Id :"+ub.getMailId()+"
" - + "
"); - - +// String pWord = ck[1].getValue(); + if (!uName.equals("") || uName != null) { + + ServletContext sct = req.getServletContext(); + UserBean ub = (UserBean) sct.getAttribute("ubean"); + RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); + rd.include(req, res); + pw.println("
" + " " + " Hello " + uName + + " ! Welcome to our new NITRTC Website" + " " + "
"); + pw.println(""); + pw.println("
Users Profile View
"); + pw.println("
" + "" + "" + "" + + "" + "" + "" + + "" + "" + "" + + "
Profile Photo :" + ub.getPhoto() + + "
User Name :" + ub.getMailId() + "
Password :" + ub.getPWord() + "
First Name :" + + ub.getFName() + "
Last Name :" + ub.getLName() + "
Address :" + ub.getAddr() + "
Phone No:" + + ub.getPhNo() + "
Mail Id :" + ub.getMailId() + "
" + "
"); + } - } - else { + } else { RequestDispatcher rd = req.getRequestDispatcher("UserLogin.html"); rd.include(req, res); pw.println("
Please Login first !
"); diff --git a/src/com/shashi/utility/DBConnection.java b/src/com/shashi/utility/DBConnection.java deleted file mode 100644 index 336a79f..0000000 --- a/src/com/shashi/utility/DBConnection.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.shashi.utility; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.util.ResourceBundle; - -public class DBConnection { - private static Connection con; - private DBConnection() {}; - static { - - ResourceBundle rb = ResourceBundle.getBundle("com.shashi.utility.database"); - - try { - Class.forName(rb.getString("driverName")); - } - catch (ClassNotFoundException e) { - e.printStackTrace(); - } - - - try { - con = DriverManager.getConnection(rb.getString("connectionString"),rb.getString("username"),rb.getString("password")); - } catch (SQLException e) { - - e.printStackTrace(); - } - } - public static Connection getCon() - { - return con; - } -} diff --git a/src/com/shashi/utility/DBUtil.java b/src/com/shashi/utility/DBUtil.java new file mode 100644 index 0000000..46cdbb4 --- /dev/null +++ b/src/com/shashi/utility/DBUtil.java @@ -0,0 +1,45 @@ +package com.shashi.utility; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.ResourceBundle; + +import com.shashi.beans.TrainException; +import com.shashi.constant.ResponseCode; + +public class DBUtil { + private static Connection con; + + private DBUtil() { + }; + + static { + + ResourceBundle rb = ResourceBundle.getBundle("com.shashi.utility.application"); + + try { + Class.forName(rb.getString("driverName")); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + + try { + System.out.println(rb.getString("connectionString")); + System.out.println(rb.getString("username")); + System.out.println(rb.getString("password")); + con = DriverManager.getConnection(rb.getString("connectionString"), rb.getString("username"), + rb.getString("password")); + System.out.println("Connection Success!!"); + } catch (SQLException e) { + + e.printStackTrace(); + } + } + + public static Connection getCon() throws TrainException { + if (con == null) + throw new TrainException(ResponseCode.DATABASE_CONNECTION_FAILURE); + return con; + } +} diff --git a/src/com/shashi/utility/application.properties b/src/com/shashi/utility/application.properties new file mode 100644 index 0000000..a737384 --- /dev/null +++ b/src/com/shashi/utility/application.properties @@ -0,0 +1,4 @@ +username=RESERVATION +password=MANAGER +driverName = oracle.jdbc.driver.OracleDriver +connectionString=jdbc:oracle:thin:@localhost:1521:orcl \ No newline at end of file diff --git a/src/com/shashi/utility/database.properties b/src/com/shashi/utility/database.properties deleted file mode 100644 index de66403..0000000 --- a/src/com/shashi/utility/database.properties +++ /dev/null @@ -1,4 +0,0 @@ -driverName = oracle.jdbc.driver.OracleDriver -connectionString = jdbc:oracle:thin:@localhost:1521:xe -username = reservation -password = manager \ No newline at end of file