Skip to content

Commit 8a046d2

Browse files
committed
Sixty-Third Commit: Refactor Register For An Event web page to handle user submitting form with empty fields
1 parent 7453a61 commit 8a046d2

File tree

5 files changed

+49
-29
lines changed

5 files changed

+49
-29
lines changed

src/java/Register.java

+26-17
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,32 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
3838
String a5 = request.getParameter("cvv");
3939
String a6 = request.getParameter("cname");
4040

41-
try{
42-
Class.forName("com.mysql.cj.jdbc.Driver");
43-
String conURL = "jdbc:mysql://localhost:3306/EventlyDB";
44-
String dbusername = "root";
45-
String dbuserpassword = "abc";
46-
Connection con;
47-
con = DriverManager.getConnection(conURL , dbusername, dbuserpassword);
48-
con.setAutoCommit(false);
49-
Statement statement = con.createStatement();
50-
String mysqlQuery = "insert into card values('"+a1+"','"+a2+"','"+a3+"','"+a4+"','"+a5+"','"+a6+"') ";
51-
statement.executeUpdate(mysqlQuery);
52-
con.commit();
53-
con.close();
54-
RequestDispatcher requestDispatcher = request.getRequestDispatcher("Payment.html");
55-
requestDispatcher.forward(request, response);
56-
}catch(ServletException | IOException | ClassNotFoundException | SQLException e){
57-
System.out.println("Exception Caught: " + e);
41+
if(a1.isBlank() && a2.isBlank() && a3.isBlank() && a4.isBlank() && a5.isBlank() && a6.isBlank()){
42+
response.setContentType("text/html");
43+
out.println("<script type=\"text/javascript\">");
44+
out.println("alert('Please Enter Event Details!!!');");
45+
out.println("</script>");
46+
RequestDispatcher requestDispatcher = request.getRequestDispatcher("Registration.html");
47+
requestDispatcher.include(request, response);
48+
}else{
49+
try{
50+
Class.forName("com.mysql.cj.jdbc.Driver");
51+
String conURL = "jdbc:mysql://localhost:3306/EventlyDB";
52+
String dbusername = "root";
53+
String dbuserpassword = "abc";
54+
Connection con;
55+
con = DriverManager.getConnection(conURL , dbusername, dbuserpassword);
56+
con.setAutoCommit(false);
57+
Statement statement = con.createStatement();
58+
String mysqlQuery = "insert into card values('"+a1+"','"+a2+"','"+a3+"','"+a4+"','"+a5+"','"+a6+"') ";
59+
statement.executeUpdate(mysqlQuery);
60+
RequestDispatcher requestDispatcher = request.getRequestDispatcher("Payment.html");
61+
requestDispatcher.forward(request, response);
62+
con.commit();
63+
con.close();
64+
}catch(ServletException | IOException | ClassNotFoundException | SQLException e){
65+
System.out.println("Exception Caught: " + e);
66+
}
5867
}
5968

6069
}

src/java/ViewEvent1.java

-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
5757
out.println("<h1 style=\"text-align: center\">Welcome To Evently ... An Event Management Portal!</h1>");
5858
out.println("<center><h1>Event Details</h1></center>");
5959
out.println("<div>");
60-
out.println("<left><p><a href=\"EventDetails.html\"><button> Event Details Page </button> </a></p></left>");
6160
out.println("<center>");
6261
out.println("<table border=1 width=50% height=50%>");
6362
out.println("<tr><th>Event Number</th><th>Event Name</th><th>Coordinator</th><th>Coordinator Contact</th><th>Fees</th><th>Venue</th><th>Date</th>");

web/EventDetails.html

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ <h1 style="text-align: center"> Event Management </h1>
1818
<body>
1919
<left><p><a href="AdminEvent.html"><button> Event/Transaction Page</button> </a></p></left>
2020
<center>
21-
<h2 style="color: black"> 1. Create Event Link </h2>
22-
<a href="CreateE.html"><button type="button" id="button">Create Event </button></a>
23-
<br><br>
24-
25-
<h2 style="color: black"> 2. View Event Link </h2>
21+
<h2 style="color: black"> 1. View Available Events </h2>
2622
<a href="ViewEvent1"><button type="button" id="button">View Event</button></a>
2723
<br><br>
24+
25+
<h2 style="color: black"> 2. Create New Event </h2>
26+
<a href="CreateE.html"><button type="button" id="button">New Event </button></a>
27+
<br><br>
2828
</center>
2929
<div>
3030
<label class="topnav-right">

web/Payment.html

+6-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ <h1 style="text-align:center">Welcome To Payment Portal </h1>
1616
<link href="https://fonts.googleapis.com/css2?family=Balsamiq+Sans&display=swap" rel="stylesheet">
1717
</head>
1818
<body>
19-
<center>
20-
<h3> Payment is Done go to back page </h3>
21-
</center>
19+
<div>
20+
<left><p><a href="Registration.html"><button> Event Registration </button> </a></p></left>
21+
<center>
22+
<h3> Payment Successful!!</h3>
23+
</center>
24+
</div>
2225
<div>
2326
<label class="topnav-right">
2427
© 1999-2022 Evently. All rights reserved.

web/Registration.html

+12-3
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,29 @@
44
Click nbfs://nbhost/SystemFileSystem/Templates/JSP_Servlet/Html.html to edit this template
55
-->
66

7-
<!-- REGISTER EVENTS PAGE -->
7+
<!-- REGISTER EVENT PAGE -->
88

99
<html>
1010
<head>
1111
<link rel="stylesheet" href="total.css">
1212
<link href="https://fonts.googleapis.com/css2?family=Balsamiq+Sans&display=swap" rel="stylesheet">
13-
<title>View Events</title>
13+
<title> Register for Event </title>
1414
<h1 style="text-align: center">Welcome To Evently ... An Event Management Portal!</h1>
1515
<meta charset="UTF-8">
1616
<meta name="viewport" content="width=device-width, initial-scale=1.0">
17-
<h2> !! Welcome All Participants !! </h2>
1817
</head>
1918
<body>
2019
<div>
20+
<left>
21+
<p>
22+
<a href="Parlogin.html"><button> Log Out </button> </a>
23+
</p>
24+
</left>
25+
<div>
26+
<center>
27+
<h2> Event Registration </h2>
28+
</center>
29+
</div>
2130
<center>
2231
<form method="post" action="Register">
2332
Enter Event Name:<br><br>

0 commit comments

Comments
 (0)