-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0f7d0b
commit a6200a3
Showing
29 changed files
with
598 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
body { | ||
font-family: Arial, sans-serif; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100vh; | ||
margin: 0; | ||
background: linear-gradient(to right, #9dff00, #ff00ee, rgb(11, 214, 255), yellow, red); | ||
color: #333; | ||
} | ||
|
||
.container { | ||
display: flex; | ||
width: 80%; | ||
height: 80vh; | ||
background-color: white; | ||
border-radius: 12px; | ||
overflow: hidden; | ||
box-shadow: 0px 8px 16px rgba(0, 0, 0, 0.15); | ||
} | ||
|
||
.left-section { | ||
flex: 1; | ||
background-image: url('../images/output-onlinegiftools.gif'); | ||
background-size: cover; | ||
background-position: center; | ||
} | ||
|
||
.right-section { | ||
flex: 1; | ||
padding: 30px; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: flex-start; | ||
align-items: center; | ||
background-color: #f8f9fa; | ||
border-radius: 12px; | ||
overflow-y: auto; /* Make the section scrollable */ | ||
max-height: 100%; | ||
} | ||
|
||
.question { | ||
font-size: 1.4em; | ||
font-weight: bold; | ||
margin-bottom: 20px; | ||
color: #555; | ||
text-align: center; | ||
} | ||
|
||
.input-group { | ||
width: 100%; | ||
margin-bottom: 15px; | ||
} | ||
|
||
.input-group input, | ||
.input-group select { | ||
width: 100%; | ||
padding: 10px; | ||
font-size: 1em; | ||
border: 1px solid #ddd; | ||
border-radius: 8px; | ||
margin-top: 8px; | ||
} | ||
|
||
.button { | ||
margin-top: 30px; | ||
padding: 12px 24px; | ||
font-size: 1em; | ||
background-color: #4CAF50; | ||
color: white; | ||
border: none; | ||
border-radius: 8px; | ||
cursor: pointer; | ||
transition: background-color 0.3s ease; | ||
} | ||
|
||
.button:hover { | ||
background-color: #45a049; | ||
} | ||
|
||
.progress-bar { | ||
width: 100%; | ||
height: 5px; | ||
background-color: #ddd; | ||
margin-bottom: 20px; | ||
border-radius: 2px; | ||
} | ||
|
||
.progress-bar-inner { | ||
height: 100%; | ||
width: 0; | ||
background-color: #4CAF50; | ||
transition: width 0.3s ease; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
body { | ||
font-family: Arial, sans-serif; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100vh; | ||
margin: 0; | ||
background: linear-gradient(to right, #9dff00, #ff00ee, rgb(11, 214, 255), yellow, red); | ||
color: #333; | ||
} | ||
|
||
.container { | ||
display: flex; | ||
width: 80%; | ||
height: 80vh; | ||
background-color: white; | ||
border-radius: 12px; | ||
overflow: hidden; | ||
box-shadow: 0px 8px 16px rgba(0, 0, 0, 0.15); | ||
} | ||
|
||
.left-section { | ||
flex: 1; | ||
background-image: url('../images/output-onlinegiftools.gif'); | ||
background-size: cover; | ||
background-position: center; | ||
} | ||
|
||
.right-section { | ||
flex: 1; | ||
padding: 30px; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: flex-start; | ||
align-items: center; | ||
background-color: #f8f9fa; | ||
border-radius: 12px; | ||
overflow-y: auto; /* Make the section scrollable */ | ||
max-height: 100%; | ||
} | ||
|
||
.question { | ||
font-size: 1.4em; | ||
font-weight: bold; | ||
margin-bottom: 20px; | ||
color: #555; | ||
text-align: center; | ||
} | ||
|
||
.input-group { | ||
width: 100%; | ||
margin-bottom: 15px; | ||
} | ||
|
||
.input-group input, | ||
.input-group select { | ||
width: 100%; | ||
padding: 10px; | ||
font-size: 1em; | ||
border: 1px solid #ddd; | ||
border-radius: 8px; | ||
margin-top: 8px; | ||
} | ||
|
||
.button { | ||
margin-top: 30px; | ||
padding: 12px 24px; | ||
font-size: 1em; | ||
background-color: #4CAF50; | ||
color: white; | ||
border: none; | ||
border-radius: 8px; | ||
cursor: pointer; | ||
transition: background-color 0.3s ease; | ||
} | ||
|
||
.button:hover { | ||
background-color: #45a049; | ||
} | ||
|
||
.progress-bar { | ||
width: 100%; | ||
height: 5px; | ||
background-color: #ddd; | ||
margin-bottom: 20px; | ||
border-radius: 2px; | ||
} | ||
|
||
.progress-bar-inner { | ||
height: 100%; | ||
width: 0; | ||
background-color: #4CAF50; | ||
transition: width 0.3s ease; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import java.io.*; | ||
import javax.servlet.*; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.*; | ||
|
||
@WebServlet("/QuestionServlete") | ||
public class ex5_e extends HttpServlet { | ||
|
||
@Override | ||
public void init() throws ServletException { | ||
// Initialize the hit count in ServletContext | ||
ServletContext context = getServletContext(); | ||
if (context.getAttribute("hitCount") == null) { | ||
context.setAttribute("hitCount", 0); | ||
} | ||
} | ||
|
||
@Override | ||
protected void doPost(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
response.setContentType("text/html"); | ||
|
||
// Increment the hit count | ||
ServletContext context = getServletContext(); | ||
synchronized (context) { | ||
int hitCount = (int) context.getAttribute("hitCount"); | ||
hitCount++; | ||
context.setAttribute("hitCount", hitCount); | ||
} | ||
|
||
// Retrieve form parameters | ||
String userName = request.getParameter("userName"); | ||
String userEmail = request.getParameter("userEmail"); | ||
String userAge = request.getParameter("userAge"); | ||
String userPassword = request.getParameter("userPassword"); | ||
String musicGenre = request.getParameter("musicGenre"); | ||
|
||
StringBuilder validationErrors = new StringBuilder(); | ||
|
||
// Validate inputs | ||
if (userName == null || userName.trim().isEmpty() || !userName.matches("[a-zA-Z ]+")) { | ||
validationErrors.append("Invalid name. "); | ||
} | ||
if (userEmail == null || userEmail.trim().isEmpty() || !userEmail.matches("^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$")) { | ||
validationErrors.append("Invalid email. "); | ||
} | ||
if (userPassword == null || userPassword.trim().isEmpty() || userPassword.length() < 8) { | ||
validationErrors.append("Password must be at least 8 characters. "); | ||
} | ||
try { | ||
int age = Integer.parseInt(userAge); | ||
if (age < 5 || age > 120) validationErrors.append("Age out of realistic range. "); | ||
} catch (NumberFormatException e) { | ||
validationErrors.append("Invalid age. "); | ||
} | ||
if (musicGenre == null || musicGenre.trim().isEmpty()) { | ||
validationErrors.append("Music genre is required. "); | ||
} | ||
|
||
PrintWriter out = response.getWriter(); | ||
if (validationErrors.length() > 0) { | ||
out.println("<html><body>"); | ||
out.println("<h2>Form Submission Error</h2>"); | ||
out.println("<p>" + validationErrors.toString() + "</p>"); | ||
out.println("<h3>Total Visits: " + context.getAttribute("hitCount") + "</h3>"); | ||
out.println("</body></html>"); | ||
} else { | ||
out.println("<html><body>"); | ||
out.println("<h2>Form Submission Successful</h2>"); | ||
out.println("<p>Your data has been successfully submitted.</p>"); | ||
out.println("<h3>Total Visits: " + context.getAttribute("hitCount") + "</h3>"); | ||
out.println("</body></html>"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Song Listening App</title> | ||
<link rel="stylesheet" href="./Exercise_5_servlet/styles/ex5_c.css"> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<div class="left-section"></div> | ||
<div class="right-section"> | ||
<form id="questionForm" action="http://localhost:8080/Tomcat-webapps/QuestionServletc1" method="POST"> | ||
<!-- Question 1: Name --> | ||
<div class="question"> | ||
<label for="userName">What name would you like to be called?</label> | ||
<div class="input-group"> | ||
<input type="text" id="userName" name="userName" placeholder="Enter your name" required> | ||
</div> | ||
</div> | ||
|
||
<!-- Question 2: Email --> | ||
<div class="question"> | ||
<label for="userEmail">What is your email?</label> | ||
<div class="input-group"> | ||
<input type="text" id="userEmail" name="userEmail" placeholder="Enter your email" required> | ||
</div> | ||
</div> | ||
|
||
<!-- Question 3: Password --> | ||
<div class="question"> | ||
<label for="userPassword">Create a password</label> | ||
<div class="input-group"> | ||
<input type="password" id="userPassword" name="userPassword" placeholder="Enter a password" required> | ||
</div> | ||
</div> | ||
|
||
<!-- Question 4: Age --> | ||
<div class="question"> | ||
<label for="userAge">How old are you?</label> | ||
<div class="input-group"> | ||
<input type="number" id="userAge" name="userAge" placeholder="Enter your age" min="0" max="120" required> | ||
</div> | ||
</div> | ||
|
||
<!-- Question 5: Favorite Genre --> | ||
<div class="question"> | ||
<label for="musicGenre">What's your favorite genre?</label> | ||
<div class="input-group"> | ||
<select id="musicGenre" name="musicGenre" required> | ||
<option value="">Select a genre</option> | ||
<option value="Pop">Pop</option> | ||
<option value="Rock">Rock</option> | ||
<option value="Jazz">Jazz</option> | ||
<option value="Classical">Classical</option> | ||
<option value="Hip-Hop">Hip-Hop</option> | ||
</select> | ||
</div> | ||
</div> | ||
|
||
<button type="submit" class="button" id="submitButton">Submit</button> | ||
</form> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
Oops, something went wrong.