Skip to content

Commit

Permalink
new changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Gokul-sami committed Nov 10, 2024
1 parent 35ea5d9 commit 4150154
Show file tree
Hide file tree
Showing 33 changed files with 1,574 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Servlet/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"java.project.sourcePaths": [
"WEB-INF\\classes"
],
"java.project.referencedLibraries": [
"c:\\xampp\\tomcat\\lib\\servlet-api.jar"
]
}
27 changes: 27 additions & 0 deletions Servlet/Death Predictor/lifespan.css
Original file line number Diff line number Diff line change
@@ -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%; }
}

64 changes: 64 additions & 0 deletions Servlet/Death Predictor/lifespan.js
Original file line number Diff line number Diff line change
@@ -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
}
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions Servlet/Form validation/script.js
Original file line number Diff line number Diff line change
@@ -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!');
}
}
62 changes: 62 additions & 0 deletions Servlet/Form validation/style.css
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 0 additions & 1 deletion Servlet/Tomcat-webapps
Submodule Tomcat-webapps deleted from 57c44e
90 changes: 90 additions & 0 deletions Servlet/WEB-INF/WEB.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<web-app>

<servlet>
<servlet-name>servletDemo</servlet-name>
<servlet-class>UserDetailsServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>servletDemo</servlet-name>
<url-pattern>/result</url-pattern>
</servlet-mapping>
<!-- -->
<servlet>
<servlet-name>deathPredictor</servlet-name>
<servlet-class>DoOrDie</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>deathPredictor</servlet-name>
<url-pattern>/deathWish</url-pattern>
</servlet-mapping>

<!-- Program p12_db1.java -->
<servlet>
<servlet-name>p12_db1</servlet-name>
<servlet-class>p12_db1</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>p12_db1</servlet-name>
<url-pattern>/db1</url-pattern>
</servlet-mapping>

<!-- Program p12_db2.java -->
<servlet>
<servlet-name>p12_db2</servlet-name>
<servlet-class>p12_db2</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>p12_db2</servlet-name>
<url-pattern>/db2</url-pattern>
</servlet-mapping>

<!-- Program p12_db3.java -->
<servlet>
<servlet-name>p12_db3</servlet-name>
<servlet-class>p12_db3</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>p12_db3</servlet-name>
<url-pattern>/db3</url-pattern>
</servlet-mapping>

<!-- Hello -->
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>Hello</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>

<!-- Form ex 5b -->
<servlet>
<servlet-name>Serveform</servlet-name>
<servlet-class>ex5_b</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Serveform</servlet-name>
<url-pattern>/formServe</url-pattern>
</servlet-mapping>

<!-- ex5 b -->
<servlet>
<servlet-name>QuestionServlet</servlet-name>
<servlet-class>ex5_b</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>QuestionServlet</servlet-name>
<url-pattern>/QuestionServlet</url-pattern>
</servlet-mapping>

</web-app>


Binary file added Servlet/WEB-INF/classes/DoOrDie.class
Binary file not shown.
Loading

0 comments on commit 4150154

Please sign in to comment.