WEB_TECH_LAB_FILE[1]
WEB_TECH_LAB_FILE[1]
SESSION: 2024-2025
NAME:- AMAN
1
INDEX
02 15/08/24 Write an HTML program to design an entry form of student details and
send it to a database server like SQL,Oracle or MS Access.
03 29/08/24 Write programs using Javascript for Web Page to display browsers
information.
Write a Java applet to display the Application Program screen i.e
04 05/09/24 calculator.
05 19/09/24 Write a program in XML for creation of DTD, which specifies set of
rules. Create a stylesheet in CSS/ XSL & display the document in
internet explorer.
Program to illustrate JDBC connectivity. Program for
06 26/09/24 maintaining databases by sending queries. Design and implement
a simple servlet book query with the help of JDBC & SQL.
Create MS Access
07 10/10/24 Install TOMCAT web server and APACHE. Access the above
developed static web pages for books website, using these servers by
putting the web pages developed.
08 17/10/24 Assume four users user1, user2, user3 and user4 having the passwords
pwd1, pwd2, pwd3 and pwd4 respectively. Write a servlet for doing
the following.1. Create a Cookie and add these four user id’s and
passwords to this Cookie. Login form and authenticate with the values
available in the cookies.
10 14/11/24 Write a JSP which inserts the details of the 3 or 4 users who register
with the web site by using registration form. Authenticate the user
when he submits the login form using the username and password from
the database.
2
Practical 1
Write HTML/Java scripts to display your CV in navigator, your Institute website,
Department Website and Tutorial website for specific subject
1
2200430100006
<li><p class="B">My date of Birth is November 0000. And hence, my age is 000.</p></li>
<li><p class="B">I know english and hindi fluently.</p></li>
<li><p class="B">Technically, I know coding in various languages like C++, C, Java, python,
html and css.</p></li>
<li><p class="B">My daily hobbies are Singing, sketching and reading books, </p></li>
</ul><br>
<br><p class="h">Previous Examinations<hr></p>
<ul type="disc" class="p">
<li><p class="B">I have completed my schooling from BBD Sr.School UP.</p></li>
<li><p class="B">My school was affiliated to Central Board Of Secondaty Education
(CBSE).</p></li>
<li><p class="B">I passed my Tenth Grade in 000 scoring 00 CGPA. </p></li>
<li><p class="B">I passed my Twelth Grade in 000 with 000. </p></li>
<li><p class="B">I cleared the UPSee exam with a general rank of .</p></li>
<li><p class="B">I scored 000 YGPA in final exams of my first year.</p></li> </ul><br>
<br><p class="h">Journey to BIET<hr></p>
<p class="Ba">I cleared the UPSEE exam with a general rank of . By this rank I got
admission in my college for the degree of BTech. At present I am in third Year, and
already like my studies here.<br>
I am here to build my career and seek for higher studies after completing my BTech here.
I scored 0000 YGPA in final exams of my second year. And aspires to score better and
better in my future, in the college.
</p>
<br><br><br><br><br>
</div>
<div class="footer">
<p>Designed by xyz, Technologies used:HTML and CSS</p>
</div>
</body>
</html>
Output:
4
2200430100006
Practical 2
Write an HTML program to design an entry form of student details and send it to a
database server like SQL,Oracle or MS Access.
<!DOCTYPE html>
<html>
<head>
<title>PHP insertion</title>
<link href="css/insert.css" rel="stylesheet">
</head>
<body>
<div class="maindiv">
<!--HTML Form -->
<div class="form_div">
<div class="title">
<h2>Insert Data In Database Using PHP.</h2>
</div>
<form action="insert.php" method="post">
<!-- Method can be set as POST for hiding values in URL-->
<h2>Form</h2>
<label>Name:</label>
<input class="input" name="name" type="text" value=""> <label>Email:</label>
<input class="input" name="email" type="text" value="">
<label>Contact:</label>
<input class="input" name="contact" type="text" value="">
<label>Address:</label>
<textarea cols="25" name="address" rows="5"></textarea><br>
<input class="submit" name="submit" type="submit" value="Insert">
</form>
</div>
</div>
</body>
</html>
<?php
$connection = mysql_connect("localhost", "root", ""); // Establishing Connection with
Server $db = mysql_select_db("colleges", $connection); // Selecting Database from
Server if(isset($_POST['submit'])){ // Fetching variables of the form which travels in URL
$name = $_POST['name']; $email
= $_POST['email'];
$contact = $_POST['contact']; $address
= $_POST['address']; if($name
!=''||$email !=''){
//Insert Query of SQL
$query = mysql_query("insert into students(student_name, student_email,
student_contact, student_address) values ('$name', '$email', '$contact', '$address')");
echo "<br/><br/><span>Data Inserted successfully...!!</span>";
} else{ echo "<p>Insertion Failed <br/> Some Fields are Blank....!!</p>";
mysql_close($connection); // Closing Connection with Server ?>
5
2200430100006
Practical 3
Write programs using Javascript for Web Page to display browsers information.
Code:
<html>
<head>
<title>Browser Information</title>
</head>
<body bgcolor = “Cornsilk”>
<h1><u>Browser Information</u></h1>
<hr>
<ul>
<script LANGUAGE="JavaScript" type="text/javascript"> document.write("<li><b>Code
Name:</b> " + navigator.appCodeName); document.write("<li><b>App Name:</b> " +
navigator.appName); document.write("<li><b>App Version:</b> " + navigator.appVersion);
document.write("<li><b>User Agent:</b> " + navigator.userAgent);
document.write("<li><b>Language:</b> " + navigator.language);
document.write("<li><b>Platform:</b> " + navigator.platform);
</script>
</ul>
<hr>
</body>
</html>
Output:
6
2200430100006
Practical 4
Write a Java applet to display the Application Program screen i.e. calculator.
Code:
import java.awt.*; import java.applet.*; import java.awt.event.*;
public class Calculator extends Applet implements ActionListener
{
TextField inp; public void init()
{
setBackground(Color.grey); setLayout(null); int i;
inp = new TextField(); inp.setBounds(150,100,270,50); this.add(inp);
Button button[] = new Button[10]; for(i=0;i<10;i++)
{
button[i] = new Button(String.valueOf(9-i));
button[i].setBounds(150+((i%3)*50),150+((i/3)*50),50,50);
this.add(button[i]); button[i].addActionListener(this);
}
Button dec=new Button("."); dec.setBounds(200,300,50,50);
this.add(dec); dec.addActionListener(this); Button clr=new Button("C");
clr.setBounds(250,300,50,50);
19 this.add(clr); clr.addActionListener(this); Button operator[] = new Button[5];
operator[0]=new Button("/"); operator[1]=new Button("*"); operator[2]=new Button("-");
operator[3]=new Button("+"); operator[4]=new Button("=");
for(i=0;i<4;i++)
{
operator[i].setBounds(300,150+(i*50),50,50);
this.add(operator[i]); operator[i].addActionListener(this);
}
operator[4].setBounds(350,300,70,50);
this.add(operator[4]); operator[4].addActionListener(this);
}
String num1=""; String op=""; String num2="";
public void actionPerformed(ActionEvent e)
{
String button = e.getActionCommand(); char ch = button.charAt(0); if(ch>='0'
&& ch<='9'|| ch=='.')
{ if (!op.equals("")) num2 = num2 + button; else num1 = num1 + button;
inp.setText(num1+op+num2);
}
20
else if(ch=='C')
{
num1 = op = num2 = ""; inp.setText("");
} else if (ch =='=') { if(!num1.equals("") &&
!num2.equals(""))
{
7
2200430100006
double temp; double n1=Double.parseDouble(num1); double
n2=Double.parseDouble(num2);
if(n2==0 && op.equals("/"))
{
inp.setText(num1+op+num2+" = Zero Division Error"); num1 = op = num2 = "";
}
if (op.equals("+"))
temp = n1 + n2; else if
(op.equals("-")) temp
= n1 - n2; else if
(op.equals("/")) temp = n1/n2; else temp = n1*n2;
inp.setText(num1+op+num2+" =
"+temp);
num1 = Double.toString(temp); op = num2 = "";
}}
21
else
{
num1 = op = num2 = ""; inp.setText("");
}
}
{
if (op.equals("") || num2.equals(""))
op = button; else
{
double temp; double n1=Double.parseDouble(num1); double
n2=Double.parseDouble(num2); if(n2==0 && op.equals("/"))
{
inp.setText(num1+op+num2+" = Zero Division Error");num1 = op = num2 = "";
}
else { if (op.equals("+")) temp = n1 + n2; else if (op.equals("-")) temp = n1 - n2; else if
(op.equals("/")) temp = n1/n2; else temp = n1*n2; num1 = Double.toString(temp); op =
button; num2 = "";
}
}
inp.setText(num1+op+num2);
}
}
}
Output:
8
2200430100006
Practical 5
Write a program in XML for creation of DTD, which specifies set of rules. Create a
stylesheet in CSS/ XSL & display the document in internet explorer.
Code:
XML File
<?xml-stylesheet href="classic.css"?>
<ARTICLE>
<HEADLINE>Lorem Ipsum</HEADLINE>
<AUTHOR>Latin literature</AUTHOR>
<PARA>
Lorem Ipsum is simply dummy text of the printing and typesetting industry
<INSTRUMENT>lorem ipsum</INSTRUMENT>
is a long established fact that a reader will be distracted by the readable content of a
page when
looking at its layout.
</PARA>
</ARTICLE>
CSS File ARTICLE { font-family: serif; background: khaki;
}
AUTHOR {
font-size: large; margin: 1em 0
}
HEADLINE { font-size: x-large; marginbottom: 1em
}
PARA
{
text-indent: 1em; text-align: justify } INSTRUMENT
{ font-style:
italic
}
9
2200430100006
Practical 6
Program to illustrate JDBC connectivity. Program for maintaining databases by
sending queries. Design and implement a simple servlet book query with the help of
JDBC & SQL. Create MS Access Database, create on ODBC link, Compile & execute JAVA
JDVC Socket.
STEPS:
//STEP 1. Import required packages
import java.sql.*; public
class FirstExample {
// JDBC driver name and database URL static final String
JDBC_DRIVER = "com.mysql.jdbc.Driver"; static final String DB_URL =
"jdbc:mysql://localhost/EMP";
// Database credentials
static final String USER = "username";
static final String PASS = "password";
10
2200430100006
}//end try
System.out.println("Goodbye!");
}//end main
}//end FirstExample
11
2200430100006
Practical 7
Install TOMCAT web server and APACHE. Access the above developed static web pages
for books website, using these servers by putting the web pages developed.
Theory:
Set the JAVA_HOME Variable
You must set the JAVA_HOME environment variable to tell Tomcat where to find Java.
Failing to properly set this variable prevents Tomcat from handling JSP pages. This
variable should list the base JDK installation directory, not the bin subdirectory.
On Windows XP, you could also go to the Start menu, select Control Panel, chooseSystem,
click on the Advanced tab, press the Environment Variables button at the bottom, and
enter the JAVA_HOME variable and value directly as:
Name: JAVA_HOME
Value: C:\jdk
Set the CLASSPATH
Since servlets and JSP are not part of the Java 2 platform, standard edition, youhave to
identify the servlet classes to the compiler. The server already knows about theservlet
classes, but the compiler (i.e., javac ) you use for development probably doesn't.So, if you
don't set your CLASSPATH, attempts to compile servlets, tag libraries, or other classes that
use the servlet and JSP APIs will fail with error messages about unknown classes.
Name: JAVA_HOME
Value: install_dir/common/lib/servlet-api.jar
Turn on Servlet Reloading
To turn on servlet reloading, edit install_dir/conf/server.xml and add a DefaultContext sub
element to the main Host element and supply true for the reloadable attribute. For
example, in Tomcat 5.0.27, search for this entry:
<Host name="localhost" debug="0" appBase="webapps" ...> and then insert the following
immediately below it:
<DefaultContext reloadable="true"/>
Be sure to make a backup copy of server.xm before making the above change.
Enable the Invoker Servlet:
The invoker servlet lets you run servlets without first making changes to your Web
application deployment descriptor. Instead, you just drop your servlet into WEB-
INF/classes and use the URL
To enable the invoker servlet, uncomment the following servlet and servlet-mapping
elements in install_dir/conf/web.xml. Finally, remember to make a backup copy of the
original version of this file before you make the changes.
<servlet>
<servlet-name>invoker</servlet-name>
<servlet-class> org.apache.catalina.servlets.InvokerServlet
</servlet-class>
…
</servlet>
12
2200430100006
Practical 8
Assume four users user1, user2, user3 and user4 having the passwords pwd1,pwd2,
pwd3 and pwd4 respectively. Write a servlet for doing the following.1. Create a Cookie
and add these four user id’s and passwords to this Cookie.2. Read the user id and
passwords entered in the Login form (week1) and authenticate with the values (user id
and passwords) available in the cookies.
Theory:
Servlet Life cycle:
1. Servlet class loading
2. Servlet Instantiation
3. call the init method
4. call the service method
5. call destroy method
Class loading and instantiation:
If you consider a servlet to be just like any other Java program, except that it runs within a
servlet container, there has to be a process of loading the class and making it ready for
requests. Servlets do not have the exact equivalent of a main method that causes them to
start execution.When a web container starts it searches for the deployment descriptor
(WEB.XML) for each of its web applications. When it finds a servlet in the descriptor it will
create an instance of the servlet class. At this point the class is considered to be loaded
(but not initialised).
ServletConfig Class:
The ServletConfig object is used by the Servlet Container to pass information to the Servlet
during its initialization. Servlet can obtain information regarding initialization parameters
and their values using different methods of ServletConfig class.
13
2200430100006
Practical 9
Install a database (Mysql or Oracle). Create a table which should contain at least the
following fields: name, password, email-id, phone number Write a java
program/servlet/JSP to connect to that database and extract data from the tables and
display them. Insert the details of the users who register with the web site, whenever a
new user clicks the submit button in the registration page.
Code:
CREATE TABLE `users` (
`user_name` VARCHAR(100) NOT NULL,
`password` VARCHAR(100) NOT NULL,
`phone_number` NUMBER(100) NOT NULL,
`email_address` VARCHAR(50) NOT NULL,
PRIMARY KEY (`user_name`)
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
OUTPUT:
14
2200430100006
Practical 10
Write a JSP which inserts the details of the 3 or 4 users who register with the web site by
using registration form. Authenticate the user when he submits the login form using the
username and password from the database.
Code: index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF8"%> <!DOCTYPE html>
<html>
<head> <style> body
{ backgroundcolor:blue; color:black; }
</style>
<meta charset="UTF-8">
<title>Welcome to Login portal</title>
</head>
<body>
<center>
<h1>Login Here !</h1>
<form action="login.jsp" method="post"> Username:<input type="text"
name="email"/><br/><br/>
Password:<input type="password" name="password"/><br/><br/>
<input type="submit" value="login"/>
<br>
<br>
<a style="color:blue" href="reg.jsp">Register for new user</a>
</center>
</form>
</body>
</html>
Login.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF8" %>
<%@page import="java.sql.*"%>
<html>
<style> body
{ background-color:blue; color:black; }
</style>
<%
String userid = request.getParameter("email"); String pwd =
request.getParameter("password"); Class.forName("com.mysql.jdbc.Driver"); 26
Connection con= DriverManager.getConnection ("jdbc:mysql ://localhost:3306
/practical14" ,"root","abc");
Statement st = con.createStatement(); ResultSet rs; rs = st.executeQuery("select * from
login where uname='" + userid + "' and pass='" + pwd
+ "'"); if (rs.next()) { session.setAttribute("userid", userid); out.println("<h1><center>welcome
" + userid+"</h1></center><br><br>"); out.println("<h3><center>You are successfully logged
15
2200430100006
in.</h3></center><br><br>"); out.println("<center><a
style=\"color:black\"href=\"index.jsp\">Logout</a></center>");
} else {
out.println("<center><h1>Invalid password </h1><br><br> <a style=\"color:black\"
href='index.jsp'>try again</a></center>");
}
%>
</html>
Reg.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-
8"%>
<!DOCTYPE html>
<html>
<head>
<style> body { background-color:blue; color:black;
}
</style>
<meta charset="UTF-8">
<title>Registration</title>
</head>
<body>
<form method="post" action="registration.jsp">
<center>
<table border="1" width="30%" cellpadding="5">
<thead>
<tr>
<th colspan="2">Registration form</th>
</tr>
</thead>
<tbody>
<tr>
<td>First Name</td>
<td><input type="text" name="fname" value="" /></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type="text" name="lname" value="" /></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email" value="" /></td>
</tr>
<tr>
<td>User Name</td>
<td><input type="text" name="uname" value="" /></td>
</tr>
<tr>
<td>Password</td>
16
2200430100006
<td><input type="password" name="pass" value="" /></td>
</tr>
<tr>
<td><input type="submit" value="Submit" /></td>
<td><input type="reset" value="Reset" /></td>
Output:
17
2200430100006