0% found this document useful (0 votes)
5 views

Web T Lab File

The document outlines a series of experiments involving HTML, CSS, and JavaScript for web development. It includes creating an institute website with departmental information, an entry form for student/employee/faculty details, a responsive blog design, a registration form with input validation using JavaScript, and an XML document for storing employee details. Each section provides code examples and styling instructions for the respective web applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Web T Lab File

The document outlines a series of experiments involving HTML, CSS, and JavaScript for web development. It includes creating an institute website with departmental information, an entry form for student/employee/faculty details, a responsive blog design, a registration form with input validation using JavaScript, and an XML document for storing employee details. Each section provides code examples and styling instructions for the respective web applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

EXPERIMENT – 01

1. Develop HTML program for designing your institute website. Display


departmental information of your institute on the website.

INSTITUTE.HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>IMS ENGINEERING COLLEGE</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f9;
}
header {
background-color: #004080;
color: white;
padding: 10px 20px;
text-align: center;
}
nav {
background-color: #0066cc;
padding: 10px 20px;
text-align: center;
}
nav a {
color: white;
text-decoration: none;
margin: 0 15px;
font-weight: bold;
}
nav a:hover {
text-decoration: underline;
2|Page
}
section {
padding: 20px;
text-align: left;
}
.department {
margin: 15px 0;
padding: 15px;
border: 1px solid #ccc;
border-radius: 5px;
background-color: #ffffff;
}
footer {
background-color: #004080;
color: white;
text-align: center;
padding: 10px 20px;
position: fixed;
bottom: 0;
width: 100%;
}
</style>
</head>
<body>
<header>
<h1>Welcome to IMS ENGINEERING COLLEGE</h1>
</header>
<nav>
<a href="#cse">CSE Department</a>
<a href="#cs">CS Department</a>
<a href="#ece">ECE Department</a>
<a href="#mech">Mechanical Department</a>
<a href="#contact">Contact Us</a>
</nav>
<section>
<h2>About Our Institute</h2>
<p>IMS ENGINEERING COLLEGE is dedicated to providing quality education and
fostering innovation among students.</p>
<h2 id="cse">Computer Science and Engineering (CSE)</h2>

3|Page
<div class="department">
<p>The CSE Department offers programs focused on software development,
artificial intelligence, and cybersecurity.</p>
</div>
<h2 id="cs">Computer Science (CS)</h2>
<div class="department">
<p>The CS Department offers programs focused on software development,
artificial intelligence,machine learning, system design and cybersecurity.</p>
</div>
<h2 id="ece">Electronics and Communication Engineering (ECE)</h2>
<div class="department">
<p>The ECE Department provides education in telecommunications, VLSI, and
IoT technologies.</p>
</div>
<h2 id="mech">Mechanical Engineering</h2>
<div class="department">
<p>The Mechanical Engineering Department specializes in manufacturing
processes, robotics, and thermodynamics.</p>
</div>
</section>
<footer>
<p>&copy; 2024 IMS ENGINEERING COLLEGE. All Rights Reserved.</p>
</footer>
</body>
</html>

OUTPUT:

4|Page
EXPERIMENT – 02
2. Develop HTML program to design an entry form for student
details/employee information/faculty details.

DETAILS.HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Entry Form</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f9f9f9;
}
header {
background-color: #004080;
color: white;
text-align: center;
padding: 15px;
}
form {
max-width: 500px;
margin: 20px auto;
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
form label {
font-weight: bold;
display: block;
margin: 10px 0 5px;
}

5|Page
form input, form select, form textarea, form button {
width: 100%;
padding: 10px;
margin-bottom: 15px;
border: 1px solid #ccc;
border-radius: 5px;
}
form button {
background-color: #004080;
color: white;
border: none;
font-weight: bold;
cursor: pointer;
}
form button:hover {
background-color: #0066cc;
}
</style>
</head>
<body>
<header>
<h1>Entry Form</h1>
</header>
<form action="#" method="post">
<label for="name">Full Name:</label>
<input type="text" id="name" name="name" placeholder="Enter your full name"
required>

<label for="email">Email:</label>
<input type="email" id="email" name="email" placeholder="Enter your email"
required>

<label for="role">Role:</label>
<select id="role" name="role" required>
<option value="">Select Role</option>
<option value="student">Student</option>
<option value="employee">Employee</option>
<option value="faculty">Faculty</option>
</select>

6|Page
<label for="department">Department:</label>
<select id="department" name="department" required>
<option value="">Select Department</option>
<option value="cs">Computer Science</option>
<option value="cse">Computer Science and Engineering</option>
<option value="ece">Electronics and Communication</option>
<option value="mech">Mechanical</option>
<option value="civil">Civil</option>
</select>

<label for="phone">Phone Number:</label>


<input type="tel" id="phone" name="phone" placeholder="Enter your phone
number" pattern="[0-9]{10}" required>

<label for="address">Address:</label>
<textarea id="address" name="address" rows="4" placeholder="Enter your
address"></textarea>

<button type="submit">Submit</button>
</form>
</body>
</html>

7|Page
OUTPUT:

8|Page
EXPERIMENT – 03
3. Develop a responsive website using CSS and HTML. Website may be
for tutorial/blogs/commercial website.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Blog</title>
<style>
/* General Reset */
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
font-family: Arial, sans-serif;
line-height: 1.6;
background-color: #f4f4f9;
color: #333;
}

header {
background: #004080;
color: white;
padding: 20px 10px;
text-align: center;
}

header h1 {
font-size: 2rem;
margin-bottom: 5px;
}

header p {

9|Page
font-size: 1rem;
}

nav {
display: flex;
justify-content: center;
background: #0066cc;
padding: 10px;
}

nav a {
color: white;
text-decoration: none;
margin: 0 15px;
font-size: 1rem;
}

nav a:hover {
text-decoration: underline;
}

.container {
max-width: 1100px;
margin: 20px auto;
padding: 0 15px;
}

.grid {
display: flex;
flex-wrap: wrap;
gap: 20px;
}

.card {
flex: 1 1 calc(33.333% - 20px);
background: white;
padding: 15px;
border-radius: 8px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);

10 | P a g e
transition: transform 0.3s ease;
}

.card:hover {
transform: scale(1.05);
}

.card img {
max-width: 100%;
border-radius: 8px;
}

.card h3 {
font-size: 1.2rem;
margin: 10px 0;
}

.card p {
font-size: 0.9rem;
color: #555;
}

footer {
background: #004080;
color: white;
text-align: center;
padding: 10px;
margin-top: 20px;
}

/* Responsive Design */
@media (max-width: 768px) {
.card {
flex: 1 1 calc(50% - 20px);
}
}

@media (max-width: 500px) {


.card {

11 | P a g e
flex: 1 1 100%;
}

nav {
flex-wrap: wrap;
}

nav a {
margin: 5px 10px;
}
}
</style>
</head>
<body>
<header>
<h1>Welcome to My Blog</h1>
<p>Your daily dose of knowledge</p>
</header>

<nav>
<a href="#home">Home</a>
<a href="#about">About</a>
<a href="#blogs">Blogs</a>
<a href="#contact">Contact</a>
</nav>

<div class="container">
<h2>Latest Posts</h2>
<div class="grid">
<div class="card">
<img src="" alt="Post Image">
<h3>Understanding Responsive Design</h3>
<p>Learn how to make your website look great on any device.</p>
</div>
<div class="card">
<img src="" alt="Post Image">
<h3>Top 10 CSS Tricks</h3>
<p>Discover the most useful CSS techniques for developers.</p>
</div>

12 | P a g e
<div class="card">
<img src="" alt="Post Image">
<h3>JavaScript for Beginners</h3>
<p>A guide to getting started with JavaScript programming.</p>
</div>
</div>
</div>

<footer>
<p>&copy; 2024 My Blog. All rights reserved.</p>
</footer>
</body>
</html>

OUTPUT:

13 | P a g e
EXPERIMENT – 04
4. Develop Java script application to validate input data in registration
form.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Registration Form Validation</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f9;
}

.container {
max-width: 500px;
margin: 50px auto;
padding: 20px;
background: white;
border-radius: 8px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

h2 {
text-align: center;
margin-bottom: 20px;
}

form label {
display: block;
font-weight: bold;
margin-bottom: 5px;
}

14 | P a g e
form input {
width: 100%;
padding: 10px;
margin-bottom: 15px;
border: 1px solid #ccc;
border-radius: 5px;
}

form button {
width: 100%;
padding: 10px;
background-color: #004080;
color: white;
border: none;
border-radius: 5px;
font-weight: bold;
cursor: pointer;
}

form button:hover {
background-color: #0066cc;
}

.error {
color: red;
font-size: 0.9rem;
margin-bottom: 10px;
}
</style>
</head>
<body>
<div class="container">
<h2>Registration Form</h2>
<form id="registrationForm">
<label for="name">Name:</label>
<input type="text" id="name" name="name" placeholder="Enter your
name">
<div id="nameError" class="error"></div>

15 | P a g e
<label for="email">Email:</label>
<input type="email" id="email" name="email" placeholder="Enter your
email">
<div id="emailError" class="error"></div>

<label for="password">Password:</label>
<input type="password" id="password" name="password"
placeholder="Enter your password">
<div id="passwordError" class="error"></div>

<label for="phone">Phone Number:</label>


<input type="tel" id="phone" name="phone" placeholder="Enter your
phone number">
<div id="phoneError" class="error"></div>

<button type="button" onclick="validateForm()">Register</button>


</form>
</div>

<script>
function validateForm() {
// Clear all errors
document.getElementById("nameError").innerText = "";
document.getElementById("emailError").innerText = "";
document.getElementById("passwordError").innerText = "";
document.getElementById("phoneError").innerText = "";

// Get input values


const name = document.getElementById("name").value.trim();
const email = document.getElementById("email").value.trim();
const password = document.getElementById("password").value.trim();
const phone = document.getElementById("phone").value.trim();

let isValid = true;

// Validate Name
if (name === "") {
document.getElementById("nameError").innerText = "Name is
required.";

16 | P a g e
isValid = false;
}

// Validate Email
const emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
if (!emailPattern.test(email)) {
document.getElementById("emailError").innerText = "Enter a valid
email address.";
isValid = false;
}

// Validate Password
if (password.length < 6) {
document.getElementById("passwordError").innerText = "Password
must be at least 6 characters long.";
isValid = false;
}

// Validate Phone Number


const phonePattern = /^[0-9]{10}$/;
if (!phonePattern.test(phone)) {
document.getElementById("phoneError").innerText = "Enter a valid
10-digit phone number.";
isValid = false;
}

// If all validations pass


if (isValid) {
alert("Registration successful!");
document.getElementById("registrationForm").reset();
}
}
</script>
</body>
</html>

OUTPUT:

17 | P a g e
18 | P a g e
19 | P a g e
EXPERIMENT – 05
5. Develop a markup language to store employee details and validate
it using DTD. Create a style sheet in CSS/ XSL & display the document
in Browser.

Employees.xml

<?xml version="1.0" encoding="UTF-8"?>


<?xml-stylesheet type="text/xsl" href="style.xsl"?>
<!DOCTYPE Employees SYSTEM "employees.dtd">
<Employees>
<Employee>
<ID>101</ID>
<Name>John Doe</Name>
<Designation>Software Engineer</Designation>
<Department>IT</Department>
<Salary>75000</Salary>
</Employee>
<Employee>
<ID>102</ID>
<Name>Jane Smith</Name>
<Designation>Project Manager</Designation>
<Department>Management</Department>
<Salary>120000</Salary>
</Employee>
</Employees>

Employees.dtd

<!ELEMENT Employees (Employee+)>


<!ELEMENT Employee (ID, Name, Designation, Department, Salary)>
<!ELEMENT ID (#PCDATA)>
<!ELEMENT Name (#PCDATA)>
<!ELEMENT Designation (#PCDATA)>
<!ELEMENT Department (#PCDATA)>

20 | P a g e
<!ELEMENT Salary (#PCDATA)>

Style.xsl

<?xml version="1.0" encoding="UTF-8"?>


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/Employees">
<html>
<head>
<title>Employee Details</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
color: #333;
}
.employee {
border: 1px solid #ccc;
padding: 10px;
margin-bottom: 15px;
background-color: #f9f9f9;
}
.id {
font-weight: bold;
color: #007BFF;
}
</style>
</head>
<body>
<h1>Employee Details</h1>
<xsl:for-each select="Employee">
<div class="employee">
<div class="id">ID: <xsl:value-of select="ID" /></div>
<div>Name: <xsl:value-of select="Name" /></div>
<div>Designation: <xsl:value-of select="Designation" /></div>
<div>Department: <xsl:value-of select="Department" /></div>
<div>Salary: <xsl:value-of select="Salary" /></div>
</div>

21 | P a g e
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
OUTPUT:

22 | P a g e
EXPERIMENT – 06
6. Develop Client Server application using Socket Programming in java.
Server.java

import java.io.*;
import java.net.*;

public class Server {


public static void main(String[] args) {
int port = 12345; // Port to listen on
try (ServerSocket serverSocket = new ServerSocket(port)) {
System.out.println("Server is listening on port " + port);

// Wait for a client connection


Socket socket = serverSocket.accept();
System.out.println("Client connected");

// Input and Output streams


InputStream input = socket.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(input));

OutputStream output = socket.getOutputStream();


PrintWriter writer = new PrintWriter(output, true);

// Read client message


String clientMessage;
while ((clientMessage = reader.readLine()) != null) {
System.out.println("Received from client: " + clientMessage);

// Send a response
writer.println("Server: Message received -> " + clientMessage);

// Exit condition
if ("bye".equalsIgnoreCase(clientMessage)) {
System.out.println("Client disconnected");
break;
}

23 | P a g e
}

socket.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}

Client.java

import java.io.*;
import java.net.*;

public class Client {


public static void main(String[] args) {
String host = "localhost"; // Server IP
int port = 12345; // Port to connect to

try (Socket socket = new Socket(host, port)) {


System.out.println("Connected to the server");

// Input and Output streams


OutputStream output = socket.getOutputStream();
PrintWriter writer = new PrintWriter(output, true);

InputStream input = socket.getInputStream();


BufferedReader reader = new BufferedReader(new InputStreamReader(input));

// Console input for user messages


BufferedReader consoleReader = new BufferedReader(new
InputStreamReader(System.in));
String message;

System.out.println("Enter messages (type 'bye' to exit):");


while (true) {

24 | P a g e
message = consoleReader.readLine(); // Read user input
writer.println(message); // Send message to server

// Exit condition
if ("bye".equalsIgnoreCase(message)) {
break;
}

String response = reader.readLine(); // Read server response


System.out.println("Server: " + response);
}

socket.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
Client OUPUT:

Server OUTPUT:

25 | P a g e
EXPERIMENT -07
7. Develop application in java servlet to add and retrieve cookies to
maintain client data.
(Assume four users user1, user2, user3 and user4 having the
passwords pwd1, pwd2, pwd3 and pwd4 respectively).

login.html
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class LoginServlet extends HttpServlet {


protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();

// Get user credentials from request


String username = request.getParameter("username");
String password = request.getParameter("password");

// Hardcoded user credentials


String[][] users = {
{"user1", "pwd1"},
{"user2", "pwd2"},
{"user3", "pwd3"},
{"user4", "pwd4"}
};

boolean authenticated = false;

for (String[] user : users) {


if (user[0].equals(username) && user[1].equals(password)) {
authenticated = true;
break;
}
}

26 | P a g e
if (authenticated) {
// Create cookies for the user
Cookie userCookie = new Cookie("username", username);
response.addCookie(userCookie);

out.println("<h2>Login Successful!</h2>");
out.println("<a href='dashboard'>Go to Dashboard</a>");
} else {
out.println("<h2>Invalid username or password!</h2>");
out.println("<a href='login.html'>Try Again</a>");
}
}
}

DashboardServlet.java

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class DashboardServlet extends HttpServlet {


protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();

// Retrieve cookies
Cookie[] cookies = request.getCookies();
String username = null;

if (cookies != null) {
for (Cookie cookie : cookies) {
if (cookie.getName().equals("username")) {
username = cookie.getValue();
break;

27 | P a g e
}
}
}

if (username != null) {
out.println("<h2>Welcome, " + username + "!</h2>");
out.println("<a href='logout'>Logout</a>");
} else {
out.println("<h2>No user logged in!</h2>");
out.println("<a href='login.html'>Login</a>");
}
}
}

LogoutServlet.java

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class LogoutServlet extends HttpServlet {


protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();

// Clear cookies
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (Cookie cookie : cookies) {
cookie.setMaxAge(0); // Delete cookie
response.addCookie(cookie);
}
}

out.println("<h2>You have been logged out!</h2>");


out.println("<a href='login.html'>Login Again</a>");
}

28 | P a g e
}

Login.html

<!DOCTYPE html>
<html>
<head>
<title>Login</title>
</head>
<body>
<h2>Login</h2>
<form action="login" method="post">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required><br><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required><br><br>
<button type="submit">Login</button>
</form>
</body>
</html>

Web.xml

<web-app>
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>DashboardServlet</servlet-name>
<servlet-class>DashboardServlet</servlet-class>

29 | P a g e
</servlet>
<servlet-mapping>
<servlet-name>DashboardServlet</servlet-name>
<url-pattern>/dashboard</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>LogoutServlet</servlet-name>
<servlet-class>LogoutServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LogoutServlet</servlet-name>
<url-pattern>/logout</url-pattern>
</servlet-mapping>
</web-app>

OUTPUT:

30 | P a g e
Experiment – 08
8. Develop Login and Registration process application using Servlet

Index.html

<!DOCTYPE html>
<html>
<head>
<title>Login & Registration</title>
</head>
<body>
<h2>Registration</h2>
<form action="register" method="post">
<label for="regUsername">Username:</label>
<input type="text" id="regUsername" name="username" required><br><br>
<label for="regPassword">Password:</label>
<input type="password" id="regPassword" name="password" required><br><br>
<button type="submit">Register</button>
</form>

<h2>Login</h2>
<form action="login" method="post">
<label for="loginUsername">Username:</label>
<input type="text" id="loginUsername" name="username" required><br><br>
<label for="loginPassword">Password:</label>
<input type="password" id="loginPassword" name="password"
required><br><br>
<button type="submit">Login</button>
</form>
</body>
</html>

RegisterServlet.java

31 | P a g e
import java.io.*;
import java.util.HashMap;
import javax.servlet.*;
import javax.servlet.http.*;

public class RegisterServlet extends HttpServlet {


private static final HashMap<String, String> users = new HashMap<>();

protected void doPost(HttpServletRequest request, HttpServletResponse response)


throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();

// Retrieve username and password


String username = request.getParameter("username");
String password = request.getParameter("password");

// Check if user already exists


if (users.containsKey(username)) {
out.println("<h2>Registration failed! User already exists.</h2>");
} else {
// Add user to the HashMap
users.put(username, password);
out.println("<h2>Registration successful! You can now log in.</h2>");
}

out.println("<a href='index.html'>Go Back</a>");


}

public static HashMap<String, String> getUsers() {


return users;
}
}

LoginServlet.java

import java.io.*;

32 | P a g e
import javax.servlet.*;
import javax.servlet.http.*;

public class LoginServlet extends HttpServlet {


protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();

// Retrieve username and password


String username = request.getParameter("username");
String password = request.getParameter("password");

// Validate credentials
if (RegisterServlet.getUsers().containsKey(username) &&
RegisterServlet.getUsers().get(username).equals(password)) {
out.println("<h2>Login successful! Welcome, " + username + ".</h2>");
} else {
out.println("<h2>Login failed! Invalid username or password.</h2>");
}

out.println("<a href='index.html'>Go Back</a>");


}
}

Web.xml

<web-app>
<servlet>
<servlet-name>RegisterServlet</servlet-name>
<servlet-class>RegisterServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RegisterServlet</servlet-name>
<url-pattern>/register</url-pattern>
</servlet-mapping>

<servlet>

33 | P a g e
<servlet-name>LoginServlet</servlet-name>
<servlet-class>LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
</web-app>

OUTPUT:

34 | P a g e
Experiment – 09

9. Develop a simple JSP application displaying user name and his city.

Index.jsp

<!DOCTYPE html>
<html>
<head>
<title>User Information</title>
</head>
<body>
<h2>Enter Your Details</h2>
<form action="display.jsp" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required><br><br>

<label for="city">City:</label>
<input type="text" id="city" name="city" required><br><br>

<button type="submit">Submit</button>
</form>
</body>
</html>

Display.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"


pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>Display User Details</title>
</head>

35 | P a g e
<body>
<h2>User Details</h2>

<%
// Retrieve data from the form
String name = request.getParameter("name");
String city = request.getParameter("city");
%>

<p><strong>Name:</strong> <%= name %></p>


<p><strong>City:</strong> <%= city %></p>

<a href="index.jsp">Go Back</a>


</body>
</html>

OUTPUT:

36 | P a g e
EXPERIMENT – 10
10. Develop a registration process using JavaBeans and JSP.

User.java

package beans;

public class User {


private String name;
private String email;
private String password;

// Getter and Setter for Name


public String getName() {
return name;
}

public void setName(String name) {


this.name = name;
}

// Getter and Setter for Email


public String getEmail() {
return email;
}

public void setEmail(String email) {


this.email = email;
}

// Getter and Setter for Password


public String getPassword() {
return password;
}

public void setPassword(String password) {


this.password = password;

37 | P a g e
}
}

Register.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"


pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>Registration Form</title>
</head>
<body>
<h2>User Registration</h2>
<form action="process.jsp" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required><br><br>

<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br><br>

<label for="password">Password:</label>
<input type="password" id="password" name="password" required><br><br>

<button type="submit">Register</button>
</form>
</body>
</html>

Process.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"


pageEncoding="UTF-8"%>
<%@ page import="beans.User" %>
<!DOCTYPE html>
<html>

38 | P a g e
<head>
<title>Registration Successful</title>
</head>
<body>
<h2>Registration Confirmation</h2>

<jsp:useBean id="user" class="beans.User" scope="session">


<jsp:setProperty name="user" property="*" />
</jsp:useBean>

<p><strong>Name:</strong> <%= user.getName() %></p>


<p><strong>Email:</strong> <%= user.getEmail() %></p>

<p>Registration successful! Thank you, <%= user.getName() %>.</p>


<a href="register.jsp">Register Another User</a>
</body>
</html>

39 | P a g e

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy