CCS375 Web Technologies Lab Manual_Print
CCS375 Web Technologies Lab Manual_Print
TABLE OF CONTENTS
Ex Marks
Pag
. Aim Outpu
Date Program Title e Prg. Viv Tota Sign
No & t&
No. Exe. a l
. Algo Result
1. Image Mapping in Html
QUESTION:
AIM:
To create a web page which includes a map and display the related
information when a hot spot is clicked in the map.
PROBLEM DESCRIPTION:
Image mapping:
An image map is an image with clickable areas.
In image mapping an image is specified with certain set of
coordinates inside the image which act as hyperlink areas to
different destinations.
Elements required:
The HTML <map> tag defines an image map.
Three basic html elements required for creating a mapped image.
Map: Used to create map of the image with clickable areas
Img: Used to display image
Area: Used within the map for defining clickable areas
PROCEDURE:
1
CODING:
Imagemap.html
<!DOCTYPE html>
<html>
<head>
<Title> Image Mapping </Title>
<h3><center>Mapping an Image </center></h3>
<body>
<p>Click on Continents to know about them</p>
<img src = "D:\world-map-151576_960_720.png" width="960" height =
"492" alt = "World Map" usemap = "#worldmap">
<map name="worldmap">
<area shape="rect" coords="184, 36, 272, 158" alt="north america"
href="https://en.wikipedia.org/wiki/North_America">
<area shape="rect" coords="282, 215, 354, 367" alt="south america"
href="https://en.wikipedia.org/wiki/South_America">
<area shape="rect" coords="506, 151, 570, 333" alt="africa"
href="https://en.wikipedia.org/wiki/Africa">
<area shape="rect" coords="618, 42, 791, 162" alt="asia"
href="https://en.wikipedia.org/wiki/Asia">
<area shape="rect" coords="509, 44, 593, 110" alt="europe"
href="https://en.wikipedia.org/wiki/Europe">
<area shape="rect" coords="786, 288, 862, 341" alt="australia"
href="https://en.wikipedia.org/wiki/Australia_(continent)">
<area shape="rect" coords="249, 463, 760, 488" alt="antartica"
href="https://en.wikipedia.org/wiki/Antarctica">
</map>
</body>
</html>
2
OUTPUT:
3
RESULT:
4
Ex. No. 2
QUESTION:
AIM:
PROBLEM DESCRIPTION:
Web Page:
A webpage is a document written in Hyper Text Markup Language
and can be viewed on any web browser.
A web page is a structured document that primarily consists of
hypertext, text with hyperlinks.
It is contained within the web server, which can be accessed by
entering the URL for that web page, and once it is loaded, it appears
on the user's web browser.
Elements required:
The <style> tag is used to define style information (CSS).
Inside the <style> element specify how HTML elements should
render in a browser.
CSS can be added to HTML documents in 3 ways:
Inline - by using the style attribute inside HTML elements.
Internal - by using a <style> element in the <head> section.
External - by using a <link> to link to an external CSS file.
PROCEDURE:
5
CODING:
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>2nd Program</title>
style.css
#body-content {
display:flex;
}
#sidebar {
padding:10px;
background-color: rgb(0, 217, 255);
height:88vh;
}
.side-items:hover{
background-color: rgb(0, 255, 255);
}
.side-items {
border-radius: 10px;
height:4rem;
width:18rem;
background-color: transparent;
border: 1px solid white;
margin-top: 3px;
font-size: 17px;
}
#content{
width:100%;
background-color: rgb(231, 231, 247);
display: flex;
8
align-items: center;
justify-content: center;
padding:50px;
text-align: center;
font-size: 25px;
}
OUTPUT:
RESULT:
9
Ex. No. 3
CLIENT-SIDE SCRIPTS FOR VALIDATING WEB FORM
CONTROLS USING DHTML.
QUESTION:
AIM:
PROBLEM DESCRIPTION:
Forms
Forms are used on webpages for the user to enter their required
details that further send to the server for processing.
A form is also known as a web form or HTML form.
JavaScript:
JavaScript makes HTML pages more dynamic and interactive.
JavaScript is a scripting language that enables you to create
dynamically updating content, control multimedia, animate images,
etc.
JavaScript is a text-based programming language that can be used
both server-side and client-side in our net applications.
JavaScript is used for developing web pages with more interactive
and user-friendly.
Elements required:
<form>
<script>
<label>
<input>
<div>
<style>
PROCEDURE:
10
1. Static web pages of an online Book store is developed with
following pages.
Home page
Registration and user Login
User profile page
Books catalogue
Payment by credit card
2. Each input box in webpage is validated using java script code
using <script> tag in html file.
3. Designed output is displayed.
CODING:
<html>
<head>
<title>A Simple Form with JavaScript Validation</title>
<script type="text/javascript">
<!--
function validate_form ( )
{
valid = true;
if ( document.contact_form.contact_name.value == "" )
{
alert ( "Please fill in the 'Your Name' box." );
valid = false;
}
if ( document.contact_form.contact_name.value != "" )
{
alert ( "Succesfull" );
valid = false;
}
return valid;
}
//-->
</script>
</head>
<body bgcolor="#FFFFFF">
<form name="contact_form" method="post" onSubmit="return
validate_form ( );">
Please Enter Your Name
<p>Your Name: <input type="text" name="contact_name"></p>
<p><input type="submit" name="send" value="Send Details"></p>
</form>
</body>
</html>
11
OUTPUT:
RESULT:
12
Ex. No. 4
QUESTION:
AIM:
PROBLEM DESCRIPTION:
Apache Tomcat:
Apache Tomcat is an open-source web server and servlet container
for Java code.
Tomcat executes programs written in the Java programming
language, and it implements many Java EE specifications, including
Jakarta Servlet, Jakarta Server Pages, and others.
Prerequisites:
Java JRE installed and configured
Administrator privileges
PROCEDURE:
13
Step 2: Install Tomcat
14
Install Tomcat via the Windows Service Installer for an automated
and wizard-guided experience.
The service installer installs the Tomcat service and runs it
automatically when the system boots.
For a portable experience, install Tomcat using the zip file and avoid
installing the service.
Easily uninstall Tomcat when it is no longer needed by deleting the
Tomcat directory, or move it around when necessary.
3. Read the License Agreement and if you agree to the terms, click I
Agree to proceed to the next step.
15
4. In the Tomcat component selection screen, choose Full in the
dropdown menu to ensure the wizard installs the Tomcat Host Manager
and Servlet and JSP examples web applications.
Alternatively, keep the default Normal installation type and click Next.
5. The next step configures the Tomcat server. For instance, enter
the Administrator login credentials or choose a
different connection port. When finished, click Next to proceed to the
next step.
16
6. The next step requires you to enter the full path to the JRE directory
on your system. The wizard auto-completes this if you have
previously set up the Java environment variables.
Click Next to proceed to the next step.
7. Choose the Tomcat server install location or keep the default one and
click Install.
17
8. Check the Run Apache Tomcat box to start the service after the
installation finishes.
Optionally, check the Show Readme box to see the Readme file. To
complete the installation, click Finish.
18
9. A popup window appears that starts the Tomcat service. After the
process completes, the window closes automatically. The Apache
Tomcat web server is now successfully installed
RESULT:
19
Ex. No. 5
(i) INVOKING SERVLETS FROM HTML FORM
QUESTION:
AIM:
PROBLEM DESCRIPTION:
Java:
Java is a widely used programming language for coding web
applications.
Java is a multi-platform, object oriented and network centric
language that can be used as a platform in itself.
Servlet:
Servlet is an application that is running on a server.
Servlet is a Java programming language class that is used to extend
the capabilities of servers that host applications accessed by means
of a request-response programming model.
There are two main types of servlets as Generic and HTTP servlet.
Elements required:
<form>
<script>
<label>
<input>
<div>
<style>
PROCEDURE:
client.html
1. Create a web page using HTML form that contains the fields such
as text, password and one submit button.
2. Set the URL of the server as the value of form’s action attribute.
3. Run the HTML program.
4. Submit the form data to the server.
20
server.java:
1. Define the class server that extends the property of the class
HttpServlet
2. Handle the request from the client by using the method service()
of HttpServlet class.
3. Get the parameter names from the HTML form by using the
method getParameterNames().
4. Get the parameter values from the HTML forms by using the
method getParameter().
5. Send the response to the client by using the method of PrintWriter
class.
CODING:
MySrv.java:
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MySrv extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01
Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
//Getting HTML parameters from Servlet
String username=request.getParameter("uname");
String password=request.getParameter("pwd");
if((username.equals("user")) && (password.equals("pswd")))
{
out.println(" <h1> Welcome to "+username);
}
else
{
21
out.println(" <h1> Registration success ");
out.println(" <a href='./index.html'> Click for Home page </a>");
}
out.println(" </BODY>");
out.println("</HTML>");
out.close();
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost( request,response);
}
}
Registration.html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY bgcolor='#e600e6'>
<form action='./MySrv' method="post"><center> <h1> <u> Login Page
</u></h1>
<h2> Username : <input type="text" name="uname"/>
Password : <input type="password" name="pwd"/>
<input type="submit" value="click me"/>
</center>
</form>
</body>
</HTML>
web.xml:
<web-app>
<servlet>
<servlet-name>MySrv</servlet-name>
<servlet-class>MySrv</servlet-class>
22
</servlet>
<servlet-mapping>
<servlet-name>MySrv</servlet-name>
<url-pattern>/MySrv</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
OUTPUT:
RESULT:
23
Ex. No. 5
(ii) SESSION TRACKING USING HIDDEN FORM FIELDS
QUESTION:
AIM:
PROBLEM DESCRIPTION:
Java:
Java is a widely used programming language for coding web
applications.
Java is a multi-platform, object oriented and network centric
language that can be used as a platform in itself.
Servlet:
Servlet is an application that is running on a server.
Servlet is a Java programming language class that is used to extend
the capabilities of servers that host applications accessed by means
of a request-response programming model.
There are two main types of servlets as Generic and HTTP servlet.
Session ID:
A session ID is a unique identification string usually a long, random
and alpha-numeric string, that is transmitted between the client and
the server.
Session IDs are usually stored in the cookies, URLs (in case url
rewriting) and hidden fields of Web pages.
Common mechanisms used for session tracking are Cookies,
SSLsessions, URL- rewriting
Elements required:
<form>
<script>
<label>
24
<input>
<div>
<style>
PROCEDURE:
1. Create a web page using HTML form that contains the fields such
as text, password and one submit button.
2. Set the URL of the server as the value of form’s action attribute.
3. Ask if the user wants to add more items or check out.
4. Include the current items as hidden fields so they'll be passed on
and submit to self.
CODING:
register.html:
<html>
<body bgcolor = "cyan">
<center>
<h1>WELCOME TO REGISTRATION PAGE</h1>
<form action="./registerone" METHOD="post">
Name: <input type="text" name = "name"><br><br>
Password: <input type="password" name="password"><br><br>
PROFESSION:
<select name="profession">
<option value="engineer">ENGINEER</option>
<option value="teacher">TEACHER</option>
<option value="businessman">BUSINESSMAN</option>
</select><br><br>
<input type="submit" value="REGISTER">
</form>
</center>
</body>
</html>
web.xml
<web-app>
<welcome-file-list>
<welcome-file>register.html</welcome-file>
25
</welcome-file-list>
<servlet>
<servlet-name>RegistrationServletOne</servlet-name>
<servlet-class>RegistrationServletOne</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RegistrationServletOne</servlet-name>
<url-pattern>/registerone</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>RegistrationServletTwo</servlet-name>
<servlet-class>RegistrationServletTwo</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RegistrationServletTwo</servlet-name>
<url-pattern>/registertwo</url-pattern>
</servlet-mapping>
</web-app>
RegistrationServletOne.java:
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class RegistrationServletOne extends HttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException
{
String name = request.getParameter("name");
26
String password = request.getParameter("password");
String profession = request.getParameter("profession");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><body bgcolor = wheat>");
out.println("<center>");
out.println("<h1>COMPLETE THE REGISTRATION</h1>");
out.println("<form action = ./registertwo method = post");
out.println("<input type = hidden name = name value =" + name +
">");
out.println("<input type = hidden name = password value =" +
password + ">");
out.println("<input type = hidden name = profession value =" +
profession + ">");
out.println("EMAIL ID:<input type =text name = email><br><br>");
out.println("PHONE NO:<input type =text name = cell><br><br>");
out.println("<input type =submit value=registernow>");
out.println("</center>");
out.println("</body></html>");
out.close();
}
}
RegistrationServletTwo.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class RegistrationServletTwo extends HttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse
response)
27
throws ServletException, IOException
{
String name = request.getParameter("name");
String password = request.getParameter("password");
String profession = request.getParameter("profession");
String email = request.getParameter("email");
String cell = request.getParameter("cell");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><body bgcolor = wheat>");
out.println("<center>");
out.println("<h1>REGISTRATION SUCCESSFUL..........</h1>");
out.println("</center>");
out.println("</body></html>");
out.close();
}
OUTPUT:
28
RESULT:
29
Ex. No. 6
ON-LINE EXAMINATION USING JSP
QUESTION:
Write programs in Java to create three-tier applications using JSP and
Databases
• For conducting on-line examination.
• For displaying student mark list. Assume that student information
is available in a database which has been stored in a database server.
AIM:
PROBLEM DESCRIPTION:
Java:
Java is a widely used programming language for coding web
applications.
Java is a multi-platform, object oriented and network centric
language that can be used as a platform in itself.
JSP
It stands for Java Server Pages.
It is a server-side technology.
It is used for creating web application.
It is used to create dynamic web content.
In this JSP tags are used to insert JAVA code into HTML pages.
It is an advanced version of Servlet Technology.
It is a Web based technology helps us to create dynamic and
platform-independent web pages.
In this, Java code can be inserted in HTML/ XML pages or both.
JSP is first converted into servlet by JSP container before
processing the client’s request.
PROCEDURE:
Steps for Creating Data Source for Microsoft Access drivers
1. Go to Control Panel and Select Administrative Tools and then select
Data Source ODBC icon. (or)
30
Go to Run (Press Window+R) and type odbcad32.exe to go Data Source
ODBC.
2.Press Add Button.
3.Choose the driver for Microsoft Access.
4.Then, Press Finish Button.
5.Type Data Source Name as ExamStudent.
6.Then Press "Select Button" and choose the database file which is
created already.
7.Then, Press "OK" Button to complete the process.
CODING:
// OnlineExam.jsp
<%@ page language="java" import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%
String SeatNum,Name;
String ans1,ans2,ans3,ans4,ans5;
int a1,a2,a3,a4,a5;
a1=a2=a3=a4=a5=0;
Connection connect=null;
31
Statement stmt=null;
ResultSet rs=null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:ExamStudent";
connect = DriverManager.getConnection(url," "," ");
if(request.getParameter("action")!=null)
{
SeatNum = request.getParameter("Seat_no");
Name = request.getParameter("Name");
ans1 =request.getParameter("group1");
if(ans1.equals("True"))
a1=5;
else
a1=0;
ans2 = request.getParameter("group2");
if(ans2.equals("True"))
a2=0;
else
a2=5;
ans3 = request.getParameter("group3");
if(ans3.equals("True"))
a3=0;
else
a3=5;
ans4 = request.getParameter("group4");
if(ans4.equals("True"))
a4=5;
else
a4=0;
ans5 = request.getParameter("group5");
if(ans5.equals("True"))
a5=0;
else
32
a5=5;
int Total=a1+a2+a3+a4+a5;
stmt = connect.createStatement();
String query = "INSERT INTO StudentTable (" + "Seat_no,Name,Marks"
+ ")
VALUES ('" +SeatNum + "', '" + Name + "', '"+Total+ "')";
int result = stmt.executeUpdate(query);
stmt.close();
stmt = connect.createStatement();
query = "SELECT * FROM StudentTable WHERE Name="+"'"+Name+"'";
rs = stmt.executeQuery(query);
%>
<html><head><title>Student Mark List</title></head>
<body bgcolor=khaki>
<center>
Students Marksheet
Name of the College : JAI SHRIRAM ENGINEERING COLLEGE
<table border="1" cellspacing="0" cellpadding="0">
<tr>
<td><b>Seat_No</b></td>
<td><b>Name</b></td>
<td><b>Marks</b></td>
</tr>
<%
while(rs.next())
{
%>
<tr>
<td><%=rs.getInt(1)%></td>
<td> <%=rs.getString(2)%></td>
<td> <%=rs.getString(3)%></td>
</tr>
33
<%
}
rs.close();
stmt.close();
connect.close();
%>
</table>
</center>
<br/> <br/><br/>
<table>
<tr><td><b>Date:<%=new java.util.Date().toString() %></td></tr>
<tr><td><b>Signature: X.Y.Z. <b></td></tr>
</table>
<div>
Click here to go back
</body>
</html>
<%}else{%>
<html>
<head><title>Online Examination</title>
<script language="javascript">
function validation(Form_obj)
{
if(Form_obj.Seat_no.value.length==0)
{
alert("Please,fill up the Seat Number");
Form_obj.Seat_no.focus();
return false;
}
if(Form_obj.Name.value.length==0)
{
alert("Please,fill up the Name");
Form_obj.Name.focus();
34
return false;
}
return true;
}
</script>
</head>
<body bgcolor=lightgreen>
<center>
Online Examination
</center>
<form action="OnlineExam.jsp" method="post"
name="entry" onSubmit="return validation(this)">
<input type="hidden" value="list" name="action">
<hr/>
<table>
<tr>
<td>
Seat Number : </td>
<td><input type="text" name="Seat_no"></td>
</tr>
<tr>
<td>
Name : </td>
<td><input type="text" name="Name" size="50"></td>
</tr>
<tr>
<td><b>Total Marks:5*5=25 </b></td>
<td></td><td></td><td></td><td><b>Time: 15 Min.</b></td>
</tr>
</table>
<hr/>
<b>1. XML enables you to collect information once and reuse it in a
variety of ways.</b><br/>
35
<input type="radio" name="group1" value="True">True
<input type="radio" name="group1" value="False">False<br>
<br/>
36
RESULT:
37
Ex. No. 7
QUESTION:
AIM:
PROBLEM DESCRIPTION:
XML:
XML is a meta-markup language that provides a format for
describing structured data.
This facilitates more structured declarations of content and more
meaningful search result across multiple platforms.
The start of XML markup elements is identified by either the less
than symbol (), the apostrophe or single quote (‘) and the double
quotation marks (“) are used by XML for markup.
To use these special characters as content within your document,
you must use the corresponding general XML entity.
Elements required:
<form>
<script>
<label>
<input>
<div>
<style>
PROCEDURE:
1. Save Students information in the XML file on the specific location.
2. Create and establish the server connection between html file and
XML file in the host
3. Get the user ID as input
38
4. Display the user’s information.
CODING:
index.html
<!DOCTYPE html>
<HTML>
<HEAD> <TITLE>Searching for XML Elements </TITLE>
<SCRIPT>
function readXMLData()
{
var xmlDocumentObject, id , name , addr, phone, email;
xmlDocumentObject=new XMLHttpRequest();
xmlDocumentObject.open("GET","userlist.xml",false);
xmlDocumentObject.send();
xmlDocumentObject=xmlDocumentObject.responseXML;
id = xmlDocumentObject.getElementsByTagName("userid");
name = xmlDocumentObject.getElementsByTagName("username");
address = xmlDocumentObject.getElementsByTagName("address");
phone = xmlDocumentObject.getElementsByTagName("phone");
email = xmlDocumentObject.getElementsByTagName("email");
for (i = 0; i < id.length; i++)
{
output=id[i].firstChild.nodeValue;
if (output == document.getElementById("myText").value)
{displayDIV.innerHTML = id[i].firstChild.nodeValue + "<br> " +
name[i].firstChild.nodeValue
+"<br> " +address[i].firstChild.nodeValue + "<br> " +
phone[i].firstChild.nodeValue+"<br>"+email[i].firstChild.nodeValue;
}}}
</SCRIPT> </HEAD>
<BODY>
<H1>Search User</H1>
<input type="text" id="myText" value="">
39
<input type="BUTTON" VALUE="Get User Details"
ONCLICK="readXMLData()">
<P>
<DIV ID="displayDIV"> </DIV>
</BODY>
</HTML>
userlist.xml:
<userlist>
<userid>usr01</userid>
<username>Abi</username>
<address>Kovai</address>
<phone>9000067078</phone>
<email>[email protected]</email>
<userid>usr02</userid>
<username>Priya</username>
<address>Tiruppur</address>
<phone>9234567890</phone>
<email>[email protected]</email>
<userid>usr03</userid>
<username>sadhana</username>
<address>Avinashi</address>
<phone>9245228888</phone>
<email>[email protected]</email>
<userid>usr04</userid>
<username>Nasrin</username>
<address>Dindugal</address>
<phone>8877665543</phone>
<email>[email protected]</email>
<userid>usr05</userid>
<username>praveena</username>
<address>Perambalur</address>
<phone>8675432109</phone>
<email>[email protected]</email>
40
</userlist>
OUTPUT:
RESULT:
41