wt (1)
wt (1)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Technology Forum</title>
<style>
body {
text-align: center;
.info {
margin-top: 20px;
display: none;
</style>
</head>
<body>
<h1>Technology Forum</h1>
<div>
<map name="techmap">
</map>
</div>
<h2>Artificial Intelligence</h2>
<p>AI involves creating intelligent machines that can mimic human behavior and decision-making.</p>
</div>
<p>IoT connects devices to the internet, enabling data collection and automation.</p>
</div>
<h2>Blockchain</h2>
<script>
function showInfo(id) {
document.getElementById(id).style.display = 'block';
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
body {
margin: 0;
padding: 0;
background-color: #f9f9f9;
color: #333;
header {
background-color: #4CAF50;
color: white;
padding: 20px;
text-align: center;
nav {
text-align: center;
margin: 20px 0;
nav a {
margin: 0 15px;
text-decoration: none;
color: #4CAF50;
font-weight: bold;
}
nav a:hover {
color: #2d7032;
.container {
max-width: 1200px;
margin: auto;
padding: 20px;
section {
margin-bottom: 40px;
padding: 20px;
background: white;
border-radius: 8px;
h2 {
color: #4CAF50;
margin-bottom: 20px;
ul {
list-style-type: none;
padding: 0;
ul li {
margin-bottom: 10px;
padding: 10px;
.rating {
color: gold;
footer {
text-align: center;
padding: 20px;
background: #333;
color: white;
</style>
</head>
<body>
<header>
</header>
<nav>
<a href="#courses">Courses</a>
<a href="#features">Features</a>
<a href="#instructors">Instructors</a>
</nav>
<div class="container">
<section id="courses">
<h2>Course Details</h2>
<ul>
</ul>
</section>
<section id="features">
<h2>Course Features</h2>
<ul>
<li>Certificate of completion</li>
</ul>
</section>
<section id="topics">
<h2>Popular Topics</h2>
<ul>
<li>Machine Learning</li>
<li>Web Development</li>
<li>Blockchain Technology</li>
<li>Cloud Computing</li>
</ul>
</section>
<section id="instructors">
<ul>
<li>John Doe - Expert in Python</li>
</ul>
</section>
<section>
<h2>Ratings</h2>
<ul>
</ul>
</section>
</div>
<footer>
</footer>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Online Banking</title>
<style>
form { margin: 20px auto; width: 300px; padding: 20px; border: 1px solid #ccc; border-radius: 8px; }
button { background: green; color: white; padding: 10px 20px; border: none; cursor: pointer; }
</style>
<script>
function validateRegistration() {
return false;
return true;
}
function validateLogin() {
if (!email || !password) {
return false;
return true;
function validateTransaction() {
return false;
alert("Transaction Successful!");
return true;
</script>
</head>
<body>
<section>
</section>
<section id="register">
<h2>Registration</h2>
<button type="submit">Register</button>
</form>
</section>
<!-- Login Form -->
<section id="login">
<h2>User Login</h2>
<button type="submit">Login</button>
</form>
</section>
<section id="transaction">
<h2>Amount Transaction</h2>
<button type="submit">Send</button>
</form>
</section>
</body>
</html>
4.
1. Download Tomcat: Go to Tomcat Download and download the latest version of Tomcat.
2. Install: Extract the downloaded file and set the environment variable CATALINA_HOME to the Tomcat
installation directory.
3. Start Tomcat:
o Navigate to the bin folder in the Tomcat directory.
o Run startup.bat (Windows) or ./startup.sh (Linux/Mac).
o Access the Tomcat server at http://localhost:8080.
xml
Copy code
<web-app>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>user1</param-name>
<param-value>password1</param-value>
</context-param>
<context-param>
<param-name>user2</param-name>
<param-value>password2</param-value>
</context-param>
</web-app>
jsp
Copy code
<html>
<head><title>Online Shopping - Login</title></head>
<body>
<h1>Login</h1>
<form action="shoppingCart.jsp" method="post">
User ID: <input type="text" name="userid"><br>
Password: <input type="password" name="password"><br>
<input type="submit" value="Login">
</form>
</body>
</html>
jsp
Copy code
<%
String userId = request.getParameter("userid");
String password = request.getParameter("password");
String validPassword = getServletContext().getInitParameter(userId);
jsp
Copy code
<%
Cookie[] cookies = request.getCookies();
String userId = null;
for (Cookie cookie : cookies) {
if (cookie.getName().equals("userId")) {
userId = cookie.getValue();
break;
}
}
if (userId != null) {
String item = request.getParameter("item");
%>
<h1>Item Added to Cart</h1>
<p>User: <%= userId %></p>
<p>Item: <%= item %></p>
<a href="shoppingCart.jsp">Go Back to Shopping Cart</a>
<%
} else {
%>
<h1>Session Expired. Please log in again.</h1>
<a href="index.jsp">Login</a>
<%
}
%>
5.
Run the following SQL commands to create the database and tables:
sql
Copy code
CREATE DATABASE RailwayReservation;
USE RailwayReservation;
xml
Copy code
<web-app>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>servlets.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>RegisterServlet</servlet-name>
<servlet-class>servlets.RegisterServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RegisterServlet</servlet-name>
<url-pattern>/register</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>BookTicketServlet</servlet-name>
<servlet-class>servlets.BookTicketServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>BookTicketServlet</servlet-name>
<url-pattern>/bookTicket</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>ViewTicketsServlet</servlet-name>
<servlet-class>servlets.ViewTicketsServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ViewTicketsServlet</servlet-name>
<url-pattern>/viewTickets</url-pattern>
</servlet-mapping>
</web-app>
Step 6: Servlets
1. LoginServlet
java
Copy code
package servlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
6.
Directory Structure
scss
Copy code
credit-card-app/
├── index.html (Home Page)
├── login.html (Login Page)
├── register.html (Registration Page)
├── profile.html (Profile Setup Page)
├── payment.html (Payment Details Page)
└── script.js (JavaScript Validation)
if (fullName === '' || email === '' || password === '' || confirmPassword === '') {
alert('All fields are required!');
return;
}
if (password !== confirmPassword) {
alert('Passwords do not match!');
return;
}
alert('Registration Successful!');
});
// Login Validation
document.getElementById('loginForm')?.addEventListener('submit', function (e) {
e.preventDefault();
// Profile Validation
document.getElementById('profileForm')?.addEventListener('submit', function (e) {
e.preventDefault();
// Payment Validation
document.getElementById('paymentForm')?.addEventListener('submit', function (e) {
e.preventDefault();
How to Run
7.
How to Run
<label for="email">Email:</label>
<input type="email" id="email" name="email" placeholder="Enter your email">
<label for="password">Password:</label>
<input type="password" id="password" name="password" placeholder="Enter your
password">
<button type="submit">Register</button>
</form>
<script>
function validateForm() {
const username = document.getElementById('username').value.trim();
const email = document.getElementById('email').value.trim();
const password = document.getElementById('password').value;
const confirmPassword = document.getElementById('confirmPassword').value;
alert("Registration successful!");
return true;
}
</script>
</body>
</html>
Features
How to Use
9.
HTML Code
html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>College Information</title>
<style>
/* Embedded Style Sheets */
body {
font-family: Arial, sans-serif;
margin: 20px;
background-color: #f4f4f9;
}
header {
text-align: center;
background-color: #007bff;
color: white;
padding: 10px 0;
border-radius: 5px;
}
section {
margin: 20px 0;
}
.info {
background-color: #eaf7ff;
padding: 15px;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
</style>
</head>
<body>
<header>
<h1>Welcome to ABC College</h1>
</header>
<section>
<h2>About Us</h2>
<p class="info" style="color: #333; font-size: 16px; line-height: 1.5;">
ABC College was established in 1990 with the aim of providing quality
education in science, arts, and technology.
Located in a serene environment, our college offers state-of-the-art
facilities and a vibrant campus life.
</p>
</section>
<section>
<h2>Departments</h2>
<ul class="info" style="font-size: 14px;">
<li style="color: #007bff;">Computer Science</li>
<li style="color: #007bff;">Electronics</li>
<li style="color: #007bff;">Business Administration</li>
<li style="color: #007bff;">Arts and Humanities</li>
</ul>
</section>
<section>
<h2>Contact Us</h2>
<p class="info" style="font-size: 16px;">
Email: <span style="color: #007bff;">info@abccollege.edu</span><br>
Phone: <span style="color: #007bff;">+123 456 7890</span><br>
Address: 123 College Lane, City, Country.
</p>
</section>
</body>
</html>
Key Features
1. Embedded CSS:
o Applied in the <style> tag within the <head> section for global styles (e.g., body, header,
section).
2. Inline CSS:
o Added directly to elements using the style attribute for specific styles (e.g., text color, font
size in <p> and <li>).
How to Use
9.
html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hospital Management System</title>
<link rel="stylesheet" href="styles.css"> <!-- External CSS -->
<style>
/* Embedded CSS */
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f9;
}
h1, h2 {
color: #2c3e50;
}
table {
width: 80%;
margin: 20px auto;
border-collapse: collapse;
}
th, td {
border: 1px solid #bdc3c7;
padding: 10px;
text-align: center;
}
th {
background-color: #3498db;
color: white;
}
tr:nth-child(even) {
background-color: #ecf0f1;
}
footer {
margin-top: 20px;
text-align: center;
background-color: #2c3e50;
color: white;
padding: 10px;
}
</style>
</head>
<body>
<header style="background-color: #3498db; color: white; padding: 20px; text-align:
center;">
<!-- Inline CSS -->
<h1>Hospital Management System</h1>
</header>
<section>
<h2>Doctor Details</h2>
<table>
<tr>
<th>Doctor ID</th>
<th>Name</th>
<th>Specialization</th>
<th>Contact</th>
</tr>
<tr>
<td>101</td>
<td>Dr. Smith</td>
<td>Cardiology</td>
<td>123-456-7890</td>
</tr>
<tr>
<td>102</td>
<td>Dr. Johnson</td>
<td>Neurology</td>
<td>987-654-3210</td>
</tr>
</table>
<h2>Patient Records</h2>
<table>
<tr>
<th>Patient ID</th>
<th>Name</th>
<th>Age</th>
<th>Diagnosis</th>
</tr>
<tr>
<td>P001</td>
<td>John Doe</td>
<td>35</td>
<td>Flu</td>
</tr>
<tr>
<td>P002</td>
<td>Jane Smith</td>
<td>42</td>
<td>Diabetes</td>
</tr>
</table>
<h2>Appointment Details</h2>
<table>
<tr>
<th>Appointment ID</th>
<th>Patient Name</th>
<th>Doctor Name</th>
<th>Date</th>
<th>Time</th>
</tr>
<tr>
<td>A001</td>
<td>John Doe</td>
<td>Dr. Smith</td>
<td>2024-12-02</td>
<td>10:00 AM</td>
</tr>
<tr>
<td>A002</td>
<td>Jane Smith</td>
<td>Dr. Johnson</td>
<td>2024-12-03</td>
<td>11:00 AM</td>
</tr>
</table>
<h2>Pharmacy Inventory</h2>
<table>
<tr>
<th>Medicine ID</th>
<th>Medicine Name</th>
<th>Quantity</th>
<th>Price</th>
</tr>
<tr>
<td>M001</td>
<td>Paracetamol</td>
<td>50</td>
<td>$2</td>
</tr>
<tr>
<td>M002</td>
<td>Insulin</td>
<td>20</td>
<td>$25</td>
</tr>
</table>
<h2>Billing Records</h2>
<table>
<tr>
<th>Bill ID</th>
<th>Patient Name</th>
<th>Total Amount</th>
<th>Status</th>
</tr>
<tr>
<td>B001</td>
<td>John Doe</td>
<td>$150</td>
<td>Paid</td>
</tr>
<tr>
<td>B002</td>
<td>Jane Smith</td>
<td>$200</td>
<td>Pending</td>
</tr>
</table>
</section>
<footer>
<p>© 2024 Hospital Management System. All Rights Reserved.</p>
</footer>
</body>
</html>
Features
1. Inline CSS: Used for the header background and text styling.
2. Embedded CSS: Styled tables, body, and footer within the <style> tag in the <head>.
3. External CSS: Used for sections and headings in the linked styles.css.
10.
PROGRAM:
//index.jsp
<html>
<head>
<title>Processing get requests with data</title>
</head>
<body>
<form action = "Servlet3" method = "get">
<b><p><label>Enter Your name Please!!
<br />
<input type = "text" name = "firstname" />
<input type = "submit" value = "Submit" />
</label></p></b>
</form>
</body>
</html>
//Servlet3.java
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;
public class Servlet3 extends HttpServlet
{
protected void doGet(HttpServletRequest request, HttpServletResponseresponse)
throws ServletException, IOException
{
String firstName = request.getParameter( "firstname" );
response.setContentType( "text/html" );
PrintWriter out = response.getWriter();
// send XHTML document to client
// start XHTML documentout.println( "<html>" );
// head section of documentout.println( "<head>" );
out.println("<title>Processing get requests with data</title>" );
out.println( "</head>" );
// body section of documentout.println( "<body>" );
out.println( "<h1>Hello " + firstName + ",<br />" );
out.println( "Welcome to Servlets!</h1>" );
out.println( "</body>" );
// end XHTML document
out.println( "</html>" );
out.close(); // close stream to complete the page
}
public String
getServletInfo() {
return "Short
description";
}
}
Program (ii)
Session tracking
GfgSession.java
// Java Program to Illustrate Creation and last-accessed
// Times for a Session
// Import required java libraries
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
// Extend HttpServlet class
public class GfgSession extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response)throws
ServletException, IOException
{
// Create a session object if it is already not
// created.
HttpSession session = request.getSession(true);
// Get session creation time.
Date createTime= new Date(session.getCreationTime());
// Get last access time of this web page.
Date lastAccessTime = new Date(session.getLastAccessedTime());
String title = "Welcome Back to GraceCollege";
Integer visitCount = new Integer(0);
String visitCountKey = new String("visitCount");
String userIDKey = new String("userID");
String userID = new String("GFG");
// Check if this is new comer on your web page.
if (session.isNew()) {
title = "Welcome to GraceCollege";
session.setAttribute(userIDKey, userID);
}
else {
visitCount = (Integer)session.getAttribute(visitCountKey);
visitCount = visitCount + 1;
userID= (String)session.getAttribute(userIDKey);
}
session.setAttribute(visitCountKey, visitCount);
// Set response content
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String docType= "<!doctype html public \"-//w3c//dtd html 4.0
"+"transitional//en\">\n";
out.println(docType + "<html>\n" + "<head><title>" + title + "</title></head>\n"+
"<body bgcolor = \"#f0f0f0\">\n"
+ "<h1 align = \"center\">" + title + "</h1>\n"
+ "<h2 align = \"center\">Gfg Session Information</h2>\n"
+ "<table border = \"1\" align = \"center\">\n"
+
"<tr bgcolor = \"#949494\">\n"
+ " <th>Session info</th><th>value</th>"
+ "</tr>\n"
+
"<tr>\n"
+ " <td>id</td>\n"
+ " <td>" + session.getId() + "</td>"
+ "</tr>\n"
+
"<tr>\n"
+ " <td>Creation Time</td>\n"
+ " <td>" + createTime + " </td>"
+ "</tr>\n"
+
"<tr>\n"
+ " <td>Time of Last Access</td>\n"
+ " <td>" + lastAccessTime + "</td>"
+ "</tr>\n"
+
"<tr>\n"
+ " <td>User ID</td>\n"
+ " <td>" + userID + "</td>"
+ "</tr>\n"
+
"<tr>\n"
+ " <td>Number of visits</td>\n"
+ " <td>" + visitCount + "</td>"
+ "</tr>\n"
+ "</table>\n"
+ "</body>"
+ "</html>");
}
}
web.xml
<web-app>
<servlet>
<servlet-name>GfgSession</servlet-name>
<servlet-class>GfgSession</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>GfgSession</servlet-name>
<url-pattern>/GfgSession</url-pattern>
</servlet-mapping>
</web-app>
11
html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Inventory Management System</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
form {
margin-bottom: 20px;
}
#result {
background-color: #f4f4f9;
padding: 15px;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
</style>
</head>
<body>
<h1>Inventory Management System</h1>
<form onsubmit="fetchProductDetails(event)">
<label for="productId">Enter Product ID:</label>
<input type="text" id="productId" required>
<button type="submit">Get Product Details</button>
</form>
<div id="result"></div>
<script>
function fetchProductDetails(event) {
event.preventDefault();
document.getElementById('result').innerHTML = `
<h2>Product Details</h2>
<p><strong>Name:</strong> ${name}</p>
<p><strong>Category:</strong> ${category}</p>
<p><strong>Price:</strong> $${price}</p>
<p><strong>Stock:</strong> ${stock} units</p>
`;
found = true;
break;
}
}
if (!found) {
document.getElementById('result').innerHTML = '<p>Product not
found.</p>';
}
})
.catch(error => {
console.error('Error fetching XML:', error);
document.getElementById('result').innerHTML = '<p>Error loading
product data.</p>';
});
}
</script>
</body>
</html>
How It Works
How to Use
12
USE RecruitmentDB;
con.close();
} catch (Exception e) {
out.println("Error: " + e.getMessage());
}
%>
<button type="submit">Submit Exam</button>
</form>
</body>
</html>
JSP for Exam Submission ( submit_exam.jsp)
jsp
Copy code
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<title>Exam Results</title>
</head>
<body>
<h1>Exam Results</h1>
<%
int score = 0;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/RecruitmentDB", "root",
"password");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM questions");
while (rs.next()) {
String correctOption = rs.getString("correct_option");
String userAnswer = request.getParameter("q" +
rs.getInt("question_id"));
if (correctOption.equals(userAnswer)) {
score++;
}
}
sql
Copy code
ALTER TABLE candidates ADD marks INT DEFAULT 0;
JSP for Displaying Mark List ( mark_list.jsp)
jsp
Copy code
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<title>Candidate Mark List</title>
</head>
<body>
<h1>Candidate Mark List</h1>
<table border="1">
<tr>
<th>Candidate ID</th>
<th>Name</th>
<th>Email</th>
<th>Marks</th>
</tr>
<%
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/RecruitmentDB", "root",
"password");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM candidates");
while (rs.next()) {
out.println("<tr>");
out.println("<td>" + rs.getInt("candidate_id") + "</td>");
out.println("<td>" + rs.getString("name") + "</td>");
out.println("<td>" + rs.getString("email") + "</td>");
out.println("<td>" + rs.getInt("marks") + "</td>");
out.println("</tr>");
}
con.close();
} catch (Exception e) {
out.println("Error: " + e.getMessage());
}
%>
</table>
</body>
</html>
How It Works
1. Three-Tier Architecture:
o Database Tier: MySQL database stores candidates, questions, and their marks.
o Application Tier: Java code in JSP interacts with the database to fetch/store data.
o Presentation Tier: HTML/CSS displays the data to the user.
2. Process:
o Candidates take the exam through exam.jsp.
o The system evaluates and displays their score in submit_exam.jsp.
o Admins or authorized users view the mark list via mark_list.jsp.
3. Setup:
o Configure a Tomcat server and deploy the JSP files.
o Update the database connection credentials in the JSP code ( username, password).
o Test the system using localhost.