PRACTICAL-1
Aim: Write HTML program for designing your institute website. Display departmental
information of your institute on the website.
Program:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Institute Website</title>
</head>
<body>
<header>
<h1>Welcome to XYZ Institute</h1>
<p>Shaping the future, one student at a time! </p>
</header>
<nav>
<a href="#about">About Us</a>
<a href="#departments">Departments</a>
<a href="#contact">Contact Us</a>
</nav>
<section id="about">
<h2>About Us</h2>
<p>XYZ Institute is a premier educational institution offering quality education in various
fields. We are dedicated to providing students with the tools and knowledge needed for success
in today's competitive world. </p>
</section>
<section id="departments">
<h2>Our Departments</h2>
<div class="department">
<h3>Computer Science Department</h3>
<p>The Computer Science Department focuses on teaching programming, AI, web
development, and cutting-edge technologies. </p>
</div>
<div class="department">
<h3>Electronics and Communication Department</h3>
<p>This department provides hands-on training in embedded systems, robotics, and
wireless communication. </p>
</div>
<div class="department">
<h3>Mechanical Engineering Department</h3>
<p>The Mechanical Engineering Department emphasizes design, manufacturing, and
thermal engineering. </p>
</div>
<div class="department">
<h3>Management Studies</h3>
<p>Our Management Department trains future leaders in business, finance, and
entrepreneurship. </p>
</div>
</section>
<section id="contact">
<h2>Contact Us</h2>
<p>Phone: +1-234-567-8900</p>
</section>
</div>
<footer>
<p>© 2024 XYZ Institute. All rights reserved. </p>
</footer>
</body>
</html>
PRACTICAL-2
Aim: Write an HTML/CSS program to design an entry form of student details.
Program:
<!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>
</head>
<body>
<h1>Student Entry Form</h1>
<form action="#" method="post">
<label for="name">Full Name:</label><br>
<input type="text" id="name" name="name" required><br><br>
<label for="rollno">Roll Number:</label><br>
<input type="text" id="rollno" name="rollno" required><br><br>
<label for="email">Email:</label><br>
<input type="email" id="email" name="email" required><br><br>
<label for="gender">Gender:</label><br>
<select id="gender" name="gender" required>
<option value="">Select</option>
<option value="male">Male</option>
<option value="female">Female</option>
</select><br><br>
<label for="department">Department:</label><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
Output:
PRACTICAL-3
Aim: Write programs using Java script for Web Page to display browsers information.
Program:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Browser Information</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
padding: 20px;
background-color: #f4f4f9;
color: #333;
}
.info-box {
border: 1px solid #ccc;
padding: 10px;
border-radius: 5px;
background-color: #fff;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
</style>
</head>
<body>
<h1>Browser Information</h1>
<div class="info-box">
<p><strong>Browser Name:</strong> <span id="browserName"></span></p>
<p><strong>Browser Version:</strong> <span id="browserVersion"></span></p>
<p><strong>Platform:</strong> <span id="platform"></span></p>
<p><strong>Language:</strong> <span id="language"></span></p>
<p><strong>User-Agent:</strong> <span id="userAgent"></span></p>
</div>
<script>
// Retrieve browser information using the navigator object
[Link]("browserName").textContent = [Link] || "N/A";
[Link]("browserVersion").textContent = [Link] || "N/A";
[Link]("platform").textContent = [Link] || "N/A";
[Link]("language").textContent = [Link] || "N/A";
[Link]("userAgent").textContent = [Link] || "N/A";
</script>
</body>
</html>
Output:
PRACTICAL-4
Aim: Writing program in XML for creation of DTD, which specifies set of rules.
Program:
XML Document ([Link])
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE bookstore SYSTEM "[Link]">
<bookstore>
<book>
<title>Learning XML</title>
<author>John Doe</author>
<price currency="USD">29.99</price>
</book>
<book>
<title>Mastering JavaScript</title>
<author>Jane Smith</author>
<price currency="EUR">35.50</price>
</book>
</bookstore>
DTD File ([Link])
<!ELEMENT bookstore (book+)>
<!ELEMENT book (title, author, price)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT price (#PCDATA)>
<!ATTLIST price
currency CDATA #REQUIRED>
Output:
PRACTICAL-5
Aim: Program to illustrate JDBC connectivity and maintaining database by sending queries.
Program:
[Link].*;
[Link].*;
class Main
{
public static void main(String a[])
{
//Creating the connection
String url = "jdbc:oracle:thin:@localhost:1521:xe";
String user = "system";
String pass = "12345";
//Entering the data
Scanner k = new Scanner([Link]);
[Link]("enter name");
String name = [Link]();
[Link]("enter roll no");
int roll = [Link]();
[Link]("enter class");
String cls = [Link]();
//Inserting data using SQL query
String sql = "insert into student1 values('"+name+"',"+roll+",'"+cls+"')";
Connection con=null;
try
{
[Link](new [Link]());
//Reference to connection interface
con = [Link](url,user,pass);
Statement st = [Link]();
int m = [Link](sql);
if (m == 1)
[Link]("inserted successfully : "+sql);
else
[Link]("insertion failed");
[Link]();
}
catch(Exception ex)
{
[Link](ex);
}
}
}
Output:
PRACTICAL-6
Aim: Install APACHE TOMCAT web server. Access the static web pages for login id, using this
server.
Theory:
1. Install Apache Tomcat
Step 1: Download Apache Tomcat
• Visit the official Apache Tomcat website: Apache Tomcat Downloads.
• Download the version suitable for your system (e.g., Tomcat 9 or later).
Step 2: Install Tomcat
• Extract the downloaded ZIP or [Link] file to a preferred location on your computer.
• This extracted folder is your Tomcat home directory.
Step 3: Configure Environment Variables (Optional)
• Set JAVA_HOME to the location of your JDK.
• Add the bin folder of the Tomcat directory to your system PATH for easier access to
commands.
Step 4: Start the Server
• Navigate to the bin folder inside the Tomcat directory.
• Run the startup script:
o On Windows: [Link]
o On macOS/Linux: ./[Link]
• Open a browser and visit [Link] to verify that Tomcat is running.
Program:
[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login Page</title>
</head>
<body>
<h1>Login Page</h1>
<form action="[Link]" method="get">
<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>
[Link]:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Welcome</title>
</head>
<body>
<h1>Welcome to the Web Application!</h1>
<p>You have successfully logged in.</p>
</body>
</html>
conf/[Link]
<Connector port="8080" protocol="HTTP/1.1" />
Output:
EXPERIMENT NO-7
Aim: Create a Cookie and add four user ids and passwords to this Cookie.
Program:
<form action="servlet1" method="post">
Name:<input type="text" name="userName"/><br/>
<input type="submit" value="go"/>
</form>
[Link]
import [Link].*;
import [Link].*;
import [Link].*;
public class FirstServlet extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response){
try{
[Link]("text/html");
PrintWriter out = [Link]();
String n=[Link]("userName");
[Link]("Welcome "+n);
Cookie ck=new Cookie("uname",n);//creating cookie object
[Link](ck);//adding cookie in the response
//creating submit button
[Link]("<form action='servlet2'>");
[Link]("<input type='submit' value='go'>");
[Link]("</form>");
[Link]();
}catch(Exception e){[Link](e);} } }
[Link]
import [Link].*;
import [Link].*;
import [Link].*;
public class SecondServlet extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response){
try{
[Link]("text/html");
PrintWriter out = [Link]();
Cookie ck[]=[Link]();
[Link]("Hello "+ck[0].getValue());
[Link]();
}catch(Exception e){[Link](e);}
}
}
[Link]
<web-app>
<servlet>
<servlet-name>s1</servlet-name>
<servlet-class>FirstServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>s1</servlet-name>
<url-pattern>/servlet1</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>s2</servlet-name>
<servlet-class>SecondServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>s2</servlet-name>
<url-pattern>/servlet2</url-pattern>
</servlet-mapping>
</web-app>
Output:
EXPERIMENT NO-8
Aim:. Write a java program/servlet/JSP to connect database and extract data from the tables
and display them.
Program:
[Link]
<%@page import="[Link]"%>
<%@page import="[Link]"%>
<%@page import="[Link]"%>
<%@page import="[Link]"%>
<%
String id = [Link]("userid");
String driver = "[Link]";
String connectionUrl = "jdbc:mysql://localhost:3306/";
String database = "test";
String userid = "root";
String password = "";
try {
[Link](driver);
} catch (ClassNotFoundException e) {
[Link]();
}
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
%>
<!DOCTYPE html>
<html>
<body>
<h1>Retrieve data from database in jsp</h1>
<table border="1">
<tr>
<td>first name</td>
<td>last name</td>
<td>City name</td>
<td>Email</td>
</tr>
<%
try{
connection = [Link](connectionUrl+database, userid, password);
statement=[Link]();
String sql ="select * from users";
resultSet =[Link](sql);
while([Link]()){
%>
<tr>
<td><%=[Link]("first_name") %></td>
<td><%=[Link]("last_name") %></td>
<td><%=[Link]("city_name") %></td>
<td><%=[Link]("email") %></td>
</tr>
<%
}
[Link]();
} catch (Exception e) {
[Link]();
}
%>
</table>
</body>
</html>
Output:
EXPERIMENT NO-9
Aim: Write a JSP which insert the details of the 3 or 4 users who register with the web site by
using registration form.
Program:
Register_1.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"[Link]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Guru Registration Form</title>
</head>
<body>
<h1>Guru Register Form</h1>
<form action="guru_register" method="post">
<table style="with: 50%">
<tr>
<td>First Name</td>
<td><input type="text" name="first_name" /></td>
</tr>
<tr> </tr>
<tr>
<td>Last Name</td>
<td><input type="text" name="last_name" /></td>
<td>UserName</td>
</td>
</tr>
<tr>
<td><input type="text" name="username" /></td>
<td>Password</td>
<td><input type="password" name="password"
</tr>
<tr>
</tr>
<tr>
<td>Address</td>
<td><input type="text" name="address" /></td>
<td>Contact No</td>
<td><input type="text" name="contact" /></td>
</body>
</html>
Guru_register.java
package demotest;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
/**
* Servlet implementation class guru_register
*/
public class guru_register extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
String first_name = [Link]("first_name");
String last_name = [Link]("last_name");
String username = [Link]("username");
String password = [Link]("password");
String address = [Link]("address");
String contact = [Link]("contact");
if(first_name.isEmpty() || last_name.isEmpty() || [Link]() ||
[Link]() || [Link]() || [Link]())
{
RequestDispatcher req =
[Link]("register_1.jsp");
[Link](request, response);
}
else
{
RequestDispatcher req =[Link]("register_2.jsp");
[Link](request, response);
}
}
}
Output:
EXPERIMENT NO-10
Aim: Design and implement a simple shopping cart example with session tracking API.
Program:
import [Link].*;
import [Link].*;
import [Link].*;
public class ShoppingCartViewerSession extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
[Link]("text/html");
PrintWriter out = [Link]();
// Get the current session object, create one if necessary.
HttpSession session = [Link](true);
// Cart items are maintained in the session object.
String[] items = (String[])[Link]("[Link]");
[Link]("<HTML><HEAD><TITLE>SessionTracker</TITLE></HEAD>");
[Link]("<BODY><H1>Session Tracking Demo</H1>");
// Print the current cart items.
[Link]("You currently have the following items in your cart:<BR>");
if (items == null) {
[Link]("<B>None</B>");
}
else {
[Link]("<UL>");
for (int i = 0; i < [Link]; i++) {
[Link]("<LI>" + items[i]);
}
[Link]("</UL>");
}
// Ask if they want to add more items or check out.
[Link]("<FORM ACTION=\"/servlet/ShoppingCart\" METHOD=POST>");
[Link]("Would you like to<BR>");
[Link]("<INPUT TYPE=submit VALUE=\" Add More Items \">");
[Link]("<INPUT TYPE=submit VALUE=\" Check Out \">");
[Link]("</FORM>");
// Offer a help page. Encode it as necessary.
[Link]("For help, click <A HREF=\"" +
[Link]("/servlet/Help?topic=ShoppingCartViewer") + "\">here</A>");
[Link]("</BODY></HTML>"); }
}
OUTPUT:
Session Tracker
Session Tracking Demo
currently have the following items in your cart:
APPLE
BANANA
MANGO
Would you like to Add More Items
Check Out