diff --git a/Servlet/.vscode/settings.json b/Servlet/.vscode/settings.json
new file mode 100644
index 0000000..971275f
--- /dev/null
+++ b/Servlet/.vscode/settings.json
@@ -0,0 +1,8 @@
+{
+ "java.project.sourcePaths": [
+ "WEB-INF\\classes"
+ ],
+ "java.project.referencedLibraries": [
+ "c:\\xampp\\tomcat\\lib\\servlet-api.jar"
+ ]
+}
\ No newline at end of file
diff --git a/Servlet/Death Predictor/lifespan.css b/Servlet/Death Predictor/lifespan.css
new file mode 100644
index 0000000..964f9d9
--- /dev/null
+++ b/Servlet/Death Predictor/lifespan.css
@@ -0,0 +1,27 @@
+.main{
+ width: 50%;
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+ margin-left: 25%;
+ margin-bottom: 20px;
+ margin-top: 20px;
+ background-color: rgb(216, 216, 216);
+ padding: 20px;
+ border-radius: 5%;
+}
+
+body {
+ height: 100vh;
+ background: linear-gradient(270deg, #ff602b, #ffeb3b, #8ec5fc, #bc75ff, #14ff20);
+ background-size: 800% 800%;
+ animation: moveBackground 20s ease infinite;
+}
+
+@keyframes moveBackground {
+ 0% { background-position: 0% 50%; }
+ 50% { background-position: 100% 50%; }
+ 100% { background-position: 0% 50%; }
+}
+
diff --git a/Servlet/Death Predictor/lifespan.js b/Servlet/Death Predictor/lifespan.js
new file mode 100644
index 0000000..94c8ae4
--- /dev/null
+++ b/Servlet/Death Predictor/lifespan.js
@@ -0,0 +1,64 @@
+// Function to check if age is within the range and gender is valid
+function validateAgeAndGender(event) {
+ var age = document.getElementById('Age').value;
+ var gender = document.getElementById('country').value;
+
+ // Check if age is between 10 and 100
+ if (age < 1 || age > 100) {
+ alert('Age must be between 1 and 100.');
+ event.preventDefault(); // stop form submission
+ return false;
+ }
+
+ // Check if gender is either "Male" or "Female"
+ if (gender !== "Male" && gender !== "Female") {
+ alert('Please select a valid gender (Male or Female).');
+ event.preventDefault(); // stop form submission
+ return false;
+ }
+
+ return true;
+}
+
+// Function to check food checkbox selection
+function validateFoodSelection(event) {
+ var checkboxes = document.querySelectorAll('input[name="food"]');
+ var maxSelection = 5 // Max allowed selections
+ var minSelection = 1;
+ var checkedCount = 0;
+
+ // count the checked boxes
+ for (var i = 0; i < checkboxes.length; i++) {
+ if (checkboxes[i].checked) {
+ checkedCount++;
+ }
+ }
+
+ // if less than 1 item is selected
+ if (checkedCount < minSelection) {
+ alert('You must select at least one food item.');
+ event.preventDefault(); // Stop form submission
+ return false;
+ }
+
+ // If more than 5 items are selected
+ if (checkedCount > maxSelection) {
+ alert('You can only select up to 5 food items.');
+ event.preventDefault(); // Stop form submission
+ return false;
+ }
+
+ return true;
+}
+
+// form submission event
+var form = document.querySelector('form');
+form.addEventListener('submit', function (event) {
+ if (!form.checkValidity()) {
+ event.preventDefault();
+ event.stopPropagation();
+ form.classList.add('was-validated');
+ } else if (!validateAgeAndGender(event) || !validateFoodSelection(event)) {
+ event.preventDefault(); // Stop form submission
+ }
+});
diff --git a/Servlet/Exercise 5 servlet/images/output-onlinegiftools.gif b/Servlet/Exercise 5 servlet/images/output-onlinegiftools.gif
new file mode 100644
index 0000000..04723f3
Binary files /dev/null and b/Servlet/Exercise 5 servlet/images/output-onlinegiftools.gif differ
diff --git a/Servlet/Form validation/script.js b/Servlet/Form validation/script.js
new file mode 100644
index 0000000..fd0532d
--- /dev/null
+++ b/Servlet/Form validation/script.js
@@ -0,0 +1,57 @@
+function submitted(event) {
+ event.preventDefault();
+
+ const nameInput = document.getElementById('userName');
+ const emailInput = document.getElementById('userEmail');
+ const phoneInput = document.getElementById('userPhno');
+ const ageInput = document.getElementById('userAge');
+ const dobInput = document.getElementById('userDob');
+ const genderInput = document.getElementById('userGender');
+
+ let isValid = true;
+
+ // Validation for input length
+ if (nameInput.value.length > 30 || emailInput.value.length > 30 || dobInput.value.length > 30) {
+ alert('Inputs should not exceed 30 characters.');
+ isValid = false;
+ }
+
+ // Validate name (only letters and spaces)
+ if (!/^[a-zA-Z\s]+$/.test(nameInput.value)) {
+ alert('Name should only contain letters and spaces.');
+ isValid = false;
+ }
+
+ // Validate email format
+ const emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
+ if (!emailPattern.test(emailInput.value)) {
+ alert('Please enter a valid email address.');
+ isValid = false;
+ }
+
+ // Validate phone number (should be at least 10 digits)
+ if (phoneInput.value.length === 10 || !/^\d+$/.test(phoneInput.value)) {
+ alert('Phone number must be 10 digits.');
+ isValid = false;
+ }
+
+ // Validate age (positive integer)
+ if (!/^\d+$/.test(ageInput.value) || ageInput.value <= 0) {
+ alert('Age must be a positive integer.');
+ isValid = false;
+ }
+ if (!ageInput.value >= 100) {
+ alert('How are you still alive!!!');
+ isValid = false;
+ }
+
+ // Validate date of birth (basic format check for demonstration)
+ if (!/^\d{2}\/\d{2}\/\d{4}$/.test(dobInput.value)) {
+ alert('Please enter Date of Birth in DD/MM/YYYY format.');
+ isValid = false;
+ }
+
+ if (isValid) {
+ alert('Form submitted successfully!');
+ }
+}
\ No newline at end of file
diff --git a/Servlet/Form validation/style.css b/Servlet/Form validation/style.css
new file mode 100644
index 0000000..71e389e
--- /dev/null
+++ b/Servlet/Form validation/style.css
@@ -0,0 +1,62 @@
+body {
+ margin: 0;
+ height: 100vh;
+ display: flex;
+ justify-content: center;
+ align-items: flex-start;
+ font-family: Arial, sans-serif;
+ background: linear-gradient(270deg, #fcb69f, #ffeb3b, #8ec5fc, #e0c3fc);
+ background-size: 800% 800%;
+ animation: moveBackground 20s ease infinite;
+}
+
+@keyframes moveBackground {
+ 0% { background-position: 0% 50%; }
+ 50% { background-position: 100% 50%; }
+ 100% { background-position: 0% 50%; }
+}
+
+h2 {
+ text-align: center;
+ font-size: 3rem;
+ margin-bottom: 30px;
+ margin-top: 30px;
+}
+
+.container {
+ display: flex;
+ align-items: flex-start;
+ flex-wrap: wrap;
+ width: 60%;
+}
+
+.video-container {
+ width: 100%;
+ max-width: 300px;
+ margin: 20px;
+}
+
+.song-gif {
+ width: 100%;
+}
+
+.form-container {
+ flex: 1;
+ padding: 20px;
+ border-radius: 10px;
+ margin: 20px;
+}
+
+.form-group label {
+ font-size: 1.3rem;
+}
+
+.form-group {
+ margin-bottom: 20px;
+}
+
+.submit-btn {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+}
\ No newline at end of file
diff --git a/Servlet/Tomcat-webapps b/Servlet/Tomcat-webapps
deleted file mode 160000
index 57c44ea..0000000
--- a/Servlet/Tomcat-webapps
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 57c44eac389b1fef1ce23a7f106588f472a01499
diff --git a/Servlet/WEB-INF/WEB.xml b/Servlet/WEB-INF/WEB.xml
new file mode 100644
index 0000000..abd71fe
--- /dev/null
+++ b/Servlet/WEB-INF/WEB.xml
@@ -0,0 +1,90 @@
+
Name: " + name + "
"); + out.println("Email: " + email + "
"); + out.println("Phone: " + phone + "
"); + out.println("Age: " + age + "
"); + out.println("Address: " + address + "
"); + out.println("Date of Birth: " + dob + "
"); + out.println("Gender: " + gender + "
"); + out.println(""); + } +} diff --git a/Servlet/WEB-INF/classes/ex5_b.class b/Servlet/WEB-INF/classes/ex5_b.class new file mode 100644 index 0000000..08f0cb2 Binary files /dev/null and b/Servlet/WEB-INF/classes/ex5_b.class differ diff --git a/Servlet/WEB-INF/classes/ex5_b.java b/Servlet/WEB-INF/classes/ex5_b.java new file mode 100644 index 0000000..15078e6 --- /dev/null +++ b/Servlet/WEB-INF/classes/ex5_b.java @@ -0,0 +1,73 @@ +import java.io.*; +import javax.servlet.*; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.*; + +@WebServlet("/QuestionServlet") +public class ex5_b extends HttpServlet { + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + response.setContentType("text/html"); + + String userName = request.getParameter("userName"); + String userAge = request.getParameter("userAge"); + String musicGenre = request.getParameter("musicGenre"); + String livePerformance = request.getParameter("livePerformance"); + String listeningFrequency = request.getParameter("listeningFrequency"); + + StringBuilder validationErrors = new StringBuilder(); + + if (userName == null || userName.trim().isEmpty()) { + validationErrors.append("Name is required." + validationErrors.toString() + "
"); + } else { + out.println("Name: " + userName + "
"); + out.println("Age: " + userAge + "
"); + out.println("Favorite Music Genre: " + musicGenre + "
"); + out.println("Live Performance Preference: " + livePerformance + "
"); + out.println("Listening Frequency: " + listeningFrequency + "
"); + } + out.println(""); + } +} diff --git a/Servlet/WEB-INF/classes/p12_db1.class b/Servlet/WEB-INF/classes/p12_db1.class new file mode 100644 index 0000000..2009b10 Binary files /dev/null and b/Servlet/WEB-INF/classes/p12_db1.class differ diff --git a/Servlet/WEB-INF/classes/p12_db1.java b/Servlet/WEB-INF/classes/p12_db1.java new file mode 100644 index 0000000..a5fe941 --- /dev/null +++ b/Servlet/WEB-INF/classes/p12_db1.java @@ -0,0 +1,62 @@ +import java.io.*; +import java.util.*; +import javax.servlet.*; +import javax.servlet.http.*; +import java.sql.*; +import java.sql.DriverManager; +import java.sql.Connection; +import java.sql.SQLException; +import javax.servlet.annotation.WebServlet; + +@WebServlet("/db1") +public class p12_db1 extends HttpServlet{ + public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + response.setContentType("text/html"); + Connection conn=null; + Statement stmt=null; + PrintWriter out = response.getWriter(); + try + { + Class.forName("com.mysql.cj.jdbc.Driver"); + //out.println(" RegNo: " + reg + "
");
+ out.println("Name: " + name + "
");
+ out.println("Department: " + dept + "
");
+ out.println("CGPA: " + cgpa + "
");
+ out.println("Availing Scholarship: " + sch + "