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 @@ + + + + servletDemo + UserDetailsServlet + + + + servletDemo + /result + + + + deathPredictor + DoOrDie + + + + deathPredictor + /deathWish + + + + + p12_db1 + p12_db1 + + + + p12_db1 + /db1 + + + + + p12_db2 + p12_db2 + + + + p12_db2 + /db2 + + + + + p12_db3 + p12_db3 + + + + p12_db3 + /db3 + + + + + HelloWorld + Hello + + + + HelloWorld + /hello + + + + + Serveform + ex5_b + + + + Serveform + /formServe + + + + + QuestionServlet + ex5_b + + + QuestionServlet + /QuestionServlet + + + + + diff --git a/Servlet/WEB-INF/classes/DoOrDie.class b/Servlet/WEB-INF/classes/DoOrDie.class new file mode 100644 index 0000000..52b49d2 Binary files /dev/null and b/Servlet/WEB-INF/classes/DoOrDie.class differ diff --git a/Servlet/WEB-INF/classes/DoOrDie.java b/Servlet/WEB-INF/classes/DoOrDie.java new file mode 100644 index 0000000..270ffe7 --- /dev/null +++ b/Servlet/WEB-INF/classes/DoOrDie.java @@ -0,0 +1,114 @@ +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet("/deathWish") +public class DoOrDie extends HttpServlet { + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + // Retrieve parameters from the form submission + String title = "Your Life Span"; + String name = request.getParameter("name"); + String age = request.getParameter("age"); + String gender = request.getParameter("gender"); + String[] food = request.getParameterValues("food"); + + Object[][] foodValues = { + {"Chappathi", 4, 4}, // food item, toxicity, energy + {"Idly", 2, 5}, + {"Dosai", 2, 6}, + {"Cornflex", 4, 8}, + {"Salad", 1, 7}, + {"Noodles", 5, 5}, + {"Bread and Jam", 3, 5}, + {"Pasta", 3, 6}, + {"Parotta", 8, 5}, + {"Upma", 3, 5} + }; + + int totalToxicity = 0; + int totalEnergy = 0; + + // Calculate total toxicity and energy from selected food items + if (food != null) { + for (String selectedFood : food) { + for (Object[] item : foodValues) { + if (item[0].equals(selectedFood)) { + totalToxicity += (int)item[1]; + totalEnergy += (int)item[2]; + break; + } + } + } + } + + // Calculate expected lifespan + int A = Integer.parseInt(age); + int G = "Male".equals(gender) ? 1 : 2; // Male = 1, Female = 2 + double expectedLifespan; + if (A > 65) { + expectedLifespan = A; + } else { + expectedLifespan = (65 - A) * (1 - (totalToxicity / 50.0)) + (totalEnergy / 2.0 * G / 2.0) + A; + } + + response.setContentType("text/html"); + PrintWriter out = response.getWriter(); + + // Generate the HTML response + out.println("" + title + ""); + out.println(""); + out.println(""); + + // Display the user's name prominently + out.println("
Hello " + name + "!
"); + + // Add the candle burning GIF and lifespan timer + out.println("
"); + out.println("Burning Candle"); + out.println("
Lifespan: 0 years
"); + out.println("
"); + + // JavaScript to manage the countdown and GIF switch + out.println(""); + out.println(""); + } +} diff --git a/Servlet/WEB-INF/classes/Hello.class b/Servlet/WEB-INF/classes/Hello.class new file mode 100644 index 0000000..a9a92b5 Binary files /dev/null and b/Servlet/WEB-INF/classes/Hello.class differ diff --git a/Servlet/WEB-INF/classes/Hello.java b/Servlet/WEB-INF/classes/Hello.java new file mode 100644 index 0000000..8ca2db2 --- /dev/null +++ b/Servlet/WEB-INF/classes/Hello.java @@ -0,0 +1,18 @@ +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.annotation.*; + +@WebServlet("/hello") +public class Hello extends HttpServlet { + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + response.setContentType("text/html"); + PrintWriter out = response.getWriter(); + out.println(""); + out.println("

Hello, World!

"); + out.println(""); + } +} diff --git a/Servlet/WEB-INF/classes/UserDetailsServlet.class b/Servlet/WEB-INF/classes/UserDetailsServlet.class new file mode 100644 index 0000000..672c49f Binary files /dev/null and b/Servlet/WEB-INF/classes/UserDetailsServlet.class differ diff --git a/Servlet/WEB-INF/classes/UserDetailsServlet.java b/Servlet/WEB-INF/classes/UserDetailsServlet.java new file mode 100644 index 0000000..a5df68d --- /dev/null +++ b/Servlet/WEB-INF/classes/UserDetailsServlet.java @@ -0,0 +1,38 @@ +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet("/result") +public class UserDetailsServlet extends HttpServlet { + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + // Retrieve parameters from the form submission + String title = "Form Inputs"; + String name = request.getParameter("userName"); + String email = request.getParameter("userEmail"); + String phone = request.getParameter("userPhno"); + String age = request.getParameter("userAge"); + String address = request.getParameter("userAddress"); + String dob = request.getParameter("userDob"); + String gender = request.getParameter("userGender"); + + response.setContentType("text/html"); + PrintWriter out = response.getWriter(); + + // Generate the HTML response + out.println("" + title + ""); + out.println("

Form Submission Details

"); + out.println("

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.
"); + } else if (!userName.matches("[a-zA-Z ]+")) { + validationErrors.append("Name can only contain alphabetic characters and spaces.
"); + } + + if (userAge == null || userAge.trim().isEmpty()) { + validationErrors.append("Age is required.
"); + } else { + try { + int age = Integer.parseInt(userAge); + if (age < 0 || age > 120) { + validationErrors.append("Please enter a realistic age (0-120).
"); + } + } catch (NumberFormatException e) { + validationErrors.append("Please enter a valid age in numbers.
"); + } + } + + if (musicGenre == null || musicGenre.trim().isEmpty()) { + validationErrors.append("Music genre is required.
"); + } else if (!musicGenre.matches("[a-zA-Z ]+")) { + validationErrors.append("Music genre should only contain alphabetic characters and spaces.
"); + } + + if (livePerformance == null || livePerformance.trim().isEmpty()) { + validationErrors.append("Live performance preference is required.
"); + } else if (!livePerformance.equalsIgnoreCase("Yes") && !livePerformance.equalsIgnoreCase("No")) { + validationErrors.append("Live performance preference should be either 'Yes' or 'No'.
"); + } + + if (listeningFrequency == null || listeningFrequency.trim().isEmpty()) { + validationErrors.append("Listening frequency is required.
"); + } else if (!listeningFrequency.matches("(?i)Daily|Weekly|Monthly|Rarely")) { + validationErrors.append("Listening frequency should be 'Daily', 'Weekly', 'Monthly', or 'Rarely'.
"); + } + + PrintWriter out = response.getWriter(); + out.println(""); + if (validationErrors.length() > 0) { + out.println("

Form Submission Error

"); + out.println("

" + validationErrors.toString() + "

"); + } else { + out.println("

Thank you for your response!

"); + 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("

into class

"); + //create a database connection using jdbc , port no used here is 3306 + // database name is college and username is root , there is no password + conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/college","root", ""); + if(conn!=null) + { + out.println("

No issues in Connection

"); + } + stmt = conn.createStatement(); + String sql; + //display all the students' marks + sql = "SELECT * FROM marks"; + ResultSet rs = stmt.executeQuery(sql); + // Extract data from result set + while(rs.next()) + { + //out.println("

into while loop

"); + //Retrieve by column name + String reg = rs.getString("RegNo"); + String name = rs.getString("Name"); + String dept = rs.getString("Dept"); + Double cgpa = rs.getDouble("CGPA"); + String sch = rs.getString("Scholarship"); + //Display values + out.println("

RegNo: " + reg + "
"); + out.println("Name: " + name + "
"); + out.println("Department: " + dept + "
"); + out.println("CGPA: " + cgpa + "
"); + out.println("Availing Scholarship: " + sch + "

"); + } + out.println(""); + // Clean-up environment + rs.close(); + stmt.close(); + conn.close(); + } + catch(Exception e) + { + System.out.print("Do not connect to DB - Error:"+e); + } + } +} \ No newline at end of file diff --git a/Servlet/WEB-INF/classes/p12_db2.class b/Servlet/WEB-INF/classes/p12_db2.class new file mode 100644 index 0000000..7314da7 Binary files /dev/null and b/Servlet/WEB-INF/classes/p12_db2.class differ diff --git a/Servlet/WEB-INF/classes/p12_db2.java b/Servlet/WEB-INF/classes/p12_db2.java new file mode 100644 index 0000000..c91be24 --- /dev/null +++ b/Servlet/WEB-INF/classes/p12_db2.java @@ -0,0 +1,60 @@ +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("/db2") +public class p12_db2 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(); + String department = request.getParameter("course"); + try + { + Class.forName("com.mysql.cj.jdbc.Driver"); + //create a database connection using jdbc , port no used here is 3306 + // database name is college and username is root , there is no password + conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/college","root", ""); + stmt = conn.createStatement(); + String sql; + //select data from table where dept matches the value given by user in form + sql = "SELECT * FROM marks where Dept = ?"; + PreparedStatement pstmt = conn.prepareStatement(sql); + pstmt.setString(1, department); + ResultSet rs = pstmt.executeQuery(); + // Extract data from result set + while(rs.next()) + { + //Retrieve by column name + String reg = rs.getString("RegNo"); + String name = rs.getString("Name"); + String dept = rs.getString("Dept"); + Double cgpa = rs.getDouble("CGPA"); + String sch = rs.getString("Scholarship"); + //Display values + out.println("

RegNo: " + reg + "
"); + out.println("Name: " + name + "
"); + out.println("Department: " + dept + "
"); + out.println("CGPA: " + cgpa + "
"); + out.println("Availing Scholarship: " + sch + "

"); + } + out.println(""); + // Clean-up environment + rs.close(); + stmt.close(); + conn.close(); + } + catch(Exception e) + { + System.out.print("Do not connect to DB - Error:"+e); + } + } +} \ No newline at end of file diff --git a/Servlet/WEB-INF/classes/p12_db3.class b/Servlet/WEB-INF/classes/p12_db3.class new file mode 100644 index 0000000..236b1a0 Binary files /dev/null and b/Servlet/WEB-INF/classes/p12_db3.class differ diff --git a/Servlet/WEB-INF/classes/p12_db3.java b/Servlet/WEB-INF/classes/p12_db3.java new file mode 100644 index 0000000..77873cd --- /dev/null +++ b/Servlet/WEB-INF/classes/p12_db3.java @@ -0,0 +1,65 @@ +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("/db3") +public class p12_db3 extends HttpServlet{ + public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + response.setContentType("text/html"); + Connection conn=null; + Statement stmt=null; + PrintWriter out = response.getWriter(); + //String department = request.getParameter("course"); + try + { + Class.forName("com.mysql.cj.jdbc.Driver"); + //create a database connection using jdbc , port no used here is 3306 + // database name is college and username is root , there is no password + conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/college","root", ""); + stmt = conn.createStatement(); + PreparedStatement pstmt = conn.prepareStatement("insert into department values(?, ?, ?)"); + pstmt.setString(1, request.getParameter("depid")); + // Same for second parameter + pstmt.setString(2, request.getParameter("depname")); + pstmt.setInt(3, Integer.valueOf(request.getParameter("depnos"))); + // Execute the insert command using executeUpdate() + // to make changes in database + pstmt.executeUpdate(); + out.println("

Database Updated

"); + //select data from table where dept matches the value given by user in form + String sql = "SELECT * FROM department"; + pstmt = conn.prepareStatement(sql); + //pstmt.setString(1, department); + ResultSet rs = pstmt.executeQuery(); + // Extract data from result set + while(rs.next()) + { + //Retrieve by column name + String did = rs.getString("DeptID"); + String dname = rs.getString("DeptName"); + int dnos = rs.getInt("NOS"); + + //Display values + out.println("

DeptID: " + did + "
"); + out.println("DeptName: " + dname + "
"); + out.println("Number of Students: " + dnos + "

"); + } + out.println(""); + // Clean-up environment + rs.close(); + stmt.close(); + conn.close(); + } + catch(Exception e) + { + System.out.print("Do not connect to DB - Error:"+e); + } + } +} \ No newline at end of file diff --git a/Servlet/WEB-INF/classes/simple_form.class b/Servlet/WEB-INF/classes/simple_form.class new file mode 100644 index 0000000..d1257a2 Binary files /dev/null and b/Servlet/WEB-INF/classes/simple_form.class differ diff --git a/Servlet/WEB-INF/classes/simple_form.java b/Servlet/WEB-INF/classes/simple_form.java new file mode 100644 index 0000000..4eb7326 --- /dev/null +++ b/Servlet/WEB-INF/classes/simple_form.java @@ -0,0 +1,67 @@ +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet("/formServe") +public class simple_form extends HttpServlet { + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + PrintWriter out = response.getWriter(); + + String name = request.getParameter("name"); + String email = request.getParameter("email"); + String password = request.getParameter("password"); + + try { + out.println(""); + out.println("Styled Form"); + out.println(""); + out.println("
"); + + if (name == null || name.isEmpty()) { + out.println("

Name is required.

"); + } + else if (!name.matches("[a-zA-Z\\s]+")) { + out.println("

Name must not contain numbers or special characters.

"); + } + else if (email == null || email.isEmpty()) { + out.println("

Email is required.

"); + } + else if (!email.matches("^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+$")) { + out.println("

Email must be in a valid format.

"); + } + else if (password == null || password.isEmpty()) { + out.println("

Password is required.

"); + } + else if (password.length() < 8 || !password.matches(".*\\d.*") || !password.matches(".*[a-zA-Z].*")) { + out.println("

Password is weak. Please choose a password with at least 8 characters, including both letters and numbers.

"); + } + else { + out.println(""); + out.println("

Form Details

"); + out.println(""); + out.println("

" + name + "

"); + out.println(""); + out.println("

" + email + "

"); + out.println("

Form submitted successfully!

"); + } + + out.println("
"); + out.println(""); + } + finally { + out.close(); + } + } +} diff --git a/Servlet/WEB-INF/lib/mysql-connector-j-8.0.31.jar b/Servlet/WEB-INF/lib/mysql-connector-j-8.0.31.jar new file mode 100644 index 0000000..f9154ff Binary files /dev/null and b/Servlet/WEB-INF/lib/mysql-connector-j-8.0.31.jar differ diff --git a/Servlet/ex5_a.html b/Servlet/ex5_a.html new file mode 100644 index 0000000..e69945a --- /dev/null +++ b/Servlet/ex5_a.html @@ -0,0 +1,14 @@ + + + + + + Redirect to Servlet + + +

Click the button to be redirected to the servlet

+
+ +
+ + \ No newline at end of file diff --git a/Servlet/ex5_b.html b/Servlet/ex5_b.html new file mode 100644 index 0000000..af4c11a --- /dev/null +++ b/Servlet/ex5_b.html @@ -0,0 +1,167 @@ + + + + + + Song Listening App + + + +
+
+
+
+
+
+
+
+ +
+
+ +
+ + +
+
+
+ + + + diff --git a/Servlet/for_later_use.html b/Servlet/for_later_use.html new file mode 100644 index 0000000..593ea19 --- /dev/null +++ b/Servlet/for_later_use.html @@ -0,0 +1,302 @@ + + + + + + Groovy + + + +
+ +
+ + + + +
+ + +
+ +
+
Your Library
+
👤
+
+ + +
+
+ Category Image +
Pop
+
+
+ Category Image +
Rock
+
+
+ Category Image +
Jazz
+
+
+ Category Image +
Hip Hop
+
+
+ Category Image +
Classical
+
+
+ Category Image +
Blues
+
+
+ Category Image +
Country
+
+
+ Category Image +
Electronic
+
+
+ + +
+

Song List

+
+ Song 1 + Artist 1 + +
+
+ Song 2 + Artist 2 + +
+
+ Song 3 + Artist 3 + +
+
+ Song 4 + Artist 4 + +
+
+
+
+ + diff --git a/Servlet/form.html b/Servlet/form.html new file mode 100644 index 0000000..072459f --- /dev/null +++ b/Servlet/form.html @@ -0,0 +1,61 @@ + + + + + + + Login page + + + + + + + +
+ +
+
+
+

User Details

+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+
+ + + diff --git a/Servlet/lifespan.html b/Servlet/lifespan.html new file mode 100644 index 0000000..0b634be --- /dev/null +++ b/Servlet/lifespan.html @@ -0,0 +1,90 @@ + + + + + + We provide death services + + + + +
+

User Information

+
+
+
+ + +
+ +
+ + +
+ +
+ + +
+
+ +
+ +
+

Food Intake

+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ + +
+
+ + + + diff --git a/Servlet/p12_db.html b/Servlet/p12_db.html new file mode 100644 index 0000000..506b48f --- /dev/null +++ b/Servlet/p12_db.html @@ -0,0 +1,42 @@ + + + + + + + Document + + +

Student Marklist


+ + Display all students' marks +
+ +

View Department Specific Mark Details

+
+ + + +
+

Insert Data into DB

+
+

Dept ID:

+ + +

Dept Name:

+ +

NOS:

+ +

+ +
+ + \ No newline at end of file diff --git a/Servlet/simple_form.html b/Servlet/simple_form.html new file mode 100644 index 0000000..97004d3 --- /dev/null +++ b/Servlet/simple_form.html @@ -0,0 +1,27 @@ + + + + + + Styled Form + + + +
+

Sign Up

+
+ + + + + + + + + + +
+
+ + + \ No newline at end of file diff --git a/Servlet/styles/simple_form.css b/Servlet/styles/simple_form.css new file mode 100644 index 0000000..1b6eb95 --- /dev/null +++ b/Servlet/styles/simple_form.css @@ -0,0 +1,66 @@ +body { + font-family: Arial, sans-serif; + background-color: #f4f4f4; + display: flex; + justify-content: center; + align-items: center; + height: 100vh; + margin: 0; + 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%; } +} + +.form-container { + background-color: #fff; + padding: 20px; + border-radius: 8px; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); + width: 300px; + display: flex; + flex-direction: column; + align-items: center; + border: 1px solid #ccc; +} + +.form-container h2 { + margin-bottom: 20px; + color: #333; +} + +.form-container label { + display: block; + margin-bottom: 5px; + color: #555; + width: 100%; +} + +.form-container input[type="text"], +.form-container input[type="email"], +.form-container input[type="password"], +.form-container input[type="submit"] { + width: 100%; + padding: 10px; + margin-bottom: 15px; + border: 1px solid #ccc; + border-radius: 4px; + box-sizing: border-box; +} + +.form-container input[type="submit"] { + background-color: #28a745; + border: none; + color: #fff; + font-size: 16px; + cursor: pointer; +} + +.form-container input[type="submit"]:hover { + background-color: #218838; +}