CCS375 Web Technologies Lab Manual (2)
CCS375 Web Technologies Lab Manual (2)
COLLEGE OF ENGINEERING
AND TECHNOLOGY
TIRUPUR-641665
(AN ISO 9001:2015 CERTIFIED
INSTITUTION)
BONAFIDE CERTIFICATE
Register Number……………………………………………..
..…………………………………………………………………………………………………………………………………….
Signatureof Signatureof
INTERNALEXAMINER EXTERNALEXAMINER
INDEX
DATE:
IMAGE MAPPING IN HTML
AIM:
To create a web page which includes a map and display the relatedinformation
when a hot spot is clicked in the map.
PROBLEM DESCRIPTION:
Image mapping:
An image map is an image with click able areas.
In image mapping an image is specified with certain set of coordinates inside the
image which act as hyperlink areas to different destinations.
Elementsrequired:
TheHTML<map>tagdefinesanimagemap.
Threebasichtmlelementsrequiredforcreatingamappedimage.
Map:Usedtocreatemapoftheimagewithclickableareas
Img:Used to display image
Area:Usedwithinthemapfordefiningclickable areas
PROCEDURE:
1. Createahtmlfilewithmaptag.
2. Set the source attribute of the img tag to the location of the image and also set the
use map attribute.
3. Specify an area with name, shape and href set to the appropriate values.
4. Repeatstep3asmanyhotspotsyouwanttoputinthemap.
5. Createhtmlfilesforeachandeveryhotspottheuserwillselect.
1
CODING:
Imagemap.html
<!DOCTYPEhtml>
<html>
<head>
<Title>ImageMapping</Title>
<h3><center>MappinganImage</center></h3>
<body>
<p>ClickonContinentstoknowaboutthem</p>
<imgsrc="D:\world-map-151576_960_720.png"width="960"height= "492" alt = "World
Map"usemap = "#worldmap">
<mapname="worldmap">
<area shape="rect" coords="184, 36, 272, 158" alt="north america"
href="https://en.wikipedia.org/wiki/North_America">
<areashape="rect"coords="282,215,354,367"alt="southamerica"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
TYPESOFCASCADINGSTYLESHEET
QUESTION:
Createawebpagewiththefollowing.
a. Cascadingstylesheets.
b. Embeddedstylesheets.
c. Inlinestylesheets.Useourcollegeinformationforthewebpages.
AIM:
To create a web page for our college which includes Cascading style sheet,
Embedded style sheet and Inline Style sheet.
PROBLEMDESCRIPTION:
WebPage:
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.
Itiscontainedwithinthewebserver,whichcanbeaccessedbyentering
theURLforthatwebpage,andonceitisloaded,itappearsontheuser's web browser.
Elementsrequired:
The<style>tag is used to define style information (CSS).
Insidethe<style>elementspecifyhowHTMLelementsshouldrenderin a browser.
CSScanbeaddedtoHTMLdocumentsin3ways:
Inline-byusingthestyleattributeinsideHTMLelements.
Internal-byusinga<style>elementinthe<head>section.
External-byusinga<link>tolinktoanexternalCSSfile.
PROCEDURE:
1. CreateaCSSfilewithStyles.
2. Createahtmlfilewithcollege information.
3. RuntheHTMLfile
5
CODING:
index.html
<!DOCTYPEhtml>
<htmllang="en">
<head>
<metacharset="UTF-8">
<title>2ndProgram</title>
<!--ExternalStyleSheet-->
<linkrel="stylesheet"href="./style.css">
<!--InternalStyleSheet-->
<style>
*{
padding:0px; margin:
0px;
}
nav{
display:flex;
background - color: aqua; justify-
content : space - between; padding:
5px;
}
.nav-items { display:
inline - flex;
height:3rem;
width:80px;
align-items: center; justify-
content:center; border-
radius: 10px;
}
</style>
6
</head>
7
<body>
<nav>
<!--InlineStyles-->
<divclass="nav-container"style="display:flex;align-items:center;">
<img src="./logo.png" alt="College logo" style="height:3rem;
margin-right : 10px; width:4rem;margin-left: 1rem;">
<h2>JaiShriramEngineeringCollege</h2>
</div>
<divclass="nav-container">
<ul>
<li class="nav-items" style="background-color: wheat; color:
black"> Home</li>
<liclass="nav-items">Branch</li>
<liclass="nav-items">Course</li>
<liclass="nav-items">Profile</li>
</ul>
</div>
</nav>
<divid="body-content">
<div id="sidebar">
<buttonclass="side-items">StudentsList</button><br>
<buttonclass="side-items">Placement</button><br>
<buttonclass="side-items">CollegeProfile</button><br>
<buttonclass="side-items">Companies</button><br>
<button class="side-items">About Barani Hydraulics India Private
Limited</button>
</div>
<div id="content">
<h4>To provide value added education in engineering, technology
andmanagementbyelevatingthestudentcommunitywithstate-of-theart infrastructure
facilities, interactive teaching, learning techniques and hands-on training through our
own industry support. Jai Shriram Engineering College was endowed by
8
ShenthilVelevanTrust in the year
2009withamottoofequippingandimplantingtheseedofhighereducation
9
blended with communal harmony to the rural community in and around the Textile City.
JSREC reinforces to impart knowledge which are innards of a meaningful life.</h4>
</div>
</div>
</body>
</html>
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;
1
1
align-items: center; justify-
content:center;
padding:50px;
text-align:center;
font-size: 25px;
}
OUTPUT:
RESULT:
1
1
Ex.No.3
CLIENT-SIDESCRIPTSFORVALIDATINGWEBFORM CONTROLS USING
DHTML.
QUESTION:
Client-SideScriptsforValidatingWebFormControlsusingDHTML.
AIM:
TovalidateWebFormControlsusingDHTML.
PROBLEMDESCRIPTION:
HTMLisusedtocreatetheform.
CSStodesignthelayoutoftheform.
JavaScripttovalidatetheform.
Forms
JavaScript:
JavaScriptmakesHTMLpagesmoredynamicandinteractive.
JavaScript is a scripting language that enables you to create
dynamicallyupdatingcontent,controlmultimedia,animateimages, etc.
JavaScriptisatext-basedprogramminglanguagethatcanbeusedboth server-side and
client-side in our net applications.
JavaScript is used for developing web pages with more interactive and user-friendly.
Elementsrequired:
<form>
<script>
<label>
<input>
<div>
<style>
10
PROCEDURE:
1. Static web pages of an online Book store is developed with following pages.
Homepage
RegistrationanduserLogin User
profile page
Books catalogue
Paymentbycreditcard
2. Eachinputboxinwebpageisvalidatedusingjavascriptcodeusing
<script>taginhtmlfile.
3. Designedoutputisdisplayed.
CODING:
<html>
<head>
<title>ASimpleFormwithJavaScriptValidation</title>
<scripttype="text/javascript">
<!--
functionvalidate_form()
{
valid=true;
if(document.contact_form.contact_name.value=="")
{
alert("Pleasefillinthe'YourName'box."); valid = false;
}
if(document.contact_form.contact_name.value!="")
{
alert("Succesfull"); valid
= false;
}
returnvalid;
}
//-->
</script>
</head>
<bodybgcolor="#FFFFFF">
<formname="contact_form"method="post"onSubmit="return validate_form ( );">
PleaseEnterYour Name
<p>YourName:<inputtype="text"name="contact_name"></p>
<p><inputtype="submit"name="send"value="SendDetails"></p>
</form>
11
</body>
</html>
OUTPUT:
RESULT:
12
Ex.No.4
INSTALLATIONOFAPACHETOMCATWEBSERVER
QUESTION:
InstallationofApacheTomcatwebserver
AIM:
ToinstallApacheTomcatWeb Server
PROBLEMDESCRIPTION:
ApacheTomcat:
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:
JavaJREinstalledandconfigured
Administratorprivileges
PROCEDURE:
Step1:DownloadTomcatforWindows
TodownloadtheTomcatinstallationfile,followthestepsbelow:
1. BrowsetotheofficialApacheTomcatwebsite.
2. LocatetheDownload sectionandclickthelatestTomcat version
available.
3. OntheDownload page,scrolldownandlocatetheBinary Distributions
area.
4. IntheCore list,dependingontheinstallationtypeyouprefer,click the download link
for the Windows Service Installer or
the32bit/64bitWindowszipfile.
13
14
Step2:InstallTomcat
15
InstallTomcatviatheWindowsServiceInstallerforanautomatedand wizard-guided
experience.
The service installer installs the Tomcat service and runs it automatically when the system
boots.
Foraportableexperience,installTomcatusingthezipfileandavoid installing the service.
EasilyuninstallTomcatwhenitisnolongerneededbydeletingthe Tomcat directory, or
move it around when necessary.
16
4. IntheTomcatcomponentselectionscreen,choose Fullinthedropdown menu to ensure
the wizard installs the Tomcat Host Manager and Servlet and JSP examples web
applications.
Alternatively,keepthedefaultNormalinstallationtypeandclickNext.
17
6. ThenextsteprequiresyoutoenterthefullpathtotheJREdirectoryon your system. The
wizard auto-completes this if you have previously set upthe Java environment variables.
ClickNexttoproceedtothenext step.
18
8. ChecktheRunApacheTomcatboxtostarttheserviceafterthe installation finishes.
Optionally,checktheShowReadmeboxtoseetheReadmefile.To complete the installation,
click Finish.
19
9. A popup window appears that starts the Tomcat service. After the
processcompletes,thewindowclosesautomatically.TheApacheTomcat web server is now
successfully installed
RESULT:
1
Ex.No.5
(i)INVOKINGSERVLETSFROMHTMLFORM
QUESTION:
WriteprograminJavausingServlets:
i.ToinvokeservletsfromHTML forms.
AIM:
TowriteajavaprogramtoinvokeservletsfromHTMLform.
PROBLEMDESCRIPTION:
Java:
Javaisawidelyusedprogramminglanguageforcodingweb applications.
Javaisamulti-platform,objectorientedandnetworkcentriclanguage that can be used as
a platform in itself.
Servlet:
Servletisanapplicationthatisrunningona server.
Servlet is a Java programming language class that is used to extend
thecapabilitiesofserversthathostapplicationsaccessedbymeansof a request-response
programming model.
TherearetwomaintypesofservletsasGenericandHTTPservlet.
Elementsrequired:
<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. SettheURLoftheserverasthevalueofform’sactionattribute.
3. RuntheHTMLprogram.
20
4.Submittheformdatatothe server.
server.java:
1. Definetheclassserverthatextendsthepropertyoftheclass HttpServlet
2. Handle the request from the client by using the method service() ofHttpServlet
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. Sendtheresponsetotheclientby usingthe methodof PrintWriterclass.
CODING:
MySrv.java:
importjava.io.IOException; import
java.io.PrintWriter;
importjavax.servlet.ServletException; import
javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse; public class
MySrv extends HttpServlet {
publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse) throws
ServletException, IOException {
response.setContentType("text/html");
PrintWriterout=response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01
Transitional//EN\">");
out.println("<HTML>");
out.println("<HEAD><TITLE>AServlet</TITLE></HEAD>"); out.println("
<BODY>");
//GettingHTMLparametersfromServlet
Stringusername=request.getParameter("uname"); String
password=request.getParameter("pwd");
if((username.equals("user"))&&(password.equals("pswd")))
{
out.println("<h1>Welcometo"+username);
}
else
21
{
out.println("<h1>Registrationsuccess");
out.println("<ahref='./index.html'>ClickforHomepage</a>");
}
out.println("</BODY>");
out.println("</HTML>"); out.close();
}
publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse) throws
ServletException, IOException {
doPost( request,response);
}
}
Registration.html:
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.0Transitional//EN">
<HTML><HEAD>
<TITLE>NewDocument</TITLE>
<METANAME="Generator" CONTENT="EditPlus">
<METANAME="Author" CONTENT="">
<METANAME="Keywords" CONTENT="">
<METANAME="Description" CONTENT="">
</HEAD>
<BODYbgcolor='#e600e6'>
<formaction='./MySrv'method="post"><center><h1><u>LoginPage</u></h1>
<h2>Username:<inputtype="text"name="uname"/> Password : <input
type="password" name="pwd"/>
<inputtype="submit"value="clickme"/>
</center>
</form>
</body>
</HTML>
web.xml:
<web-app>
<servlet>
<servlet-name>MySrv</servlet-name>
22
<servlet-class>MySrv</servlet-class>
</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)SESSIONTRACKINGUSINGHIDDENFORMFIELDS
QUESTION:
WriteprograminJavausingServlets:
ii. Sessiontrackingusinghiddenformfieldsand Sessiontrackingforahit count
AIM:
TowriteaJavaProgramforSessionTrackingUsingHiddenForm Fields.
PROBLEMDESCRIPTION:
Java:
Javaisawidelyusedprogramminglanguageforcodingweb applications.
Javaisamulti-platform,objectorientedandnetworkcentriclanguage that can be used as
a platform in itself.
Servlet:
Servletisanapplicationthatisrunningona server.
Servlet is a Java programming language class that is used to extend
thecapabilitiesofserversthathostapplicationsaccessedbymeansof a request-response
programming model.
TherearetwomaintypesofservletsasGenericandHTTPservlet.
SessionID:
A session ID is a unique identification string usually a long, random andalpha-
numericstring,thatistransmittedbetweentheclientand the server.
SessionIDsareusuallystoredinthecookies,URLs(incaseurl rewriting) and
hidden fields of Web pages.
CommonmechanismsusedforsessiontrackingareCookies, SSLsessions,
URL- rewriting
Elementsrequired:
<form>
<script>
24
<label>
<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. SettheURLoftheserverasthevalueofform’sactionattribute.
3. Askiftheuserwantstoaddmoreitemsorcheckout.
4. Includethecurrentitemsashiddenfieldssothey'llbepassedonand submit to self.
CODING:
register.html:
<html>
<bodybgcolor="cyan">
<center>
<h1>WELCOMETOREGISTRATIONPAGE</h1>
<form action="./registerone" METHOD="post">
Name:<inputtype="text"name="name"><br><br>
Password:<inputtype="password"name="password"><br><br>PROFESSION:
<selectname="profession">
<optionvalue="engineer">ENGINEER</option>
<optionvalue="teacher">TEACHER</option>
<optionvalue="businessman">BUSINESSMAN</option>
</select><br><br>
<inputtype="submit"value="REGISTER">
</form>
</center>
</body>
</html>
web.xml
<web-app>
<welcome-file-list>
25
<welcome-file>register.html</welcome-file>
</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:
importjava.io.IOException; import
java.io.PrintWriter;
importjavax.servlet.ServletException; import
javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
publicclassRegistrationServletOneextendsHttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse
response)
throwsServletException,IOException
26
{
27
Stringname=request.getParameter("name");
String password = request.getParameter("password");
Stringprofession=request.getParameter("profession");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><bodybgcolor=wheat>");
out.println("<center>");
out.println("<h1>COMPLETETHEREGISTRATION</h1>");
out.println("<form action = ./registertwo method = post");
out.println("<inputtype=hiddenname=namevalue="+name+">");
out.println("<input type = hidden name = password value =" + password + ">");
out.println("<inputtype=hiddenname=professionvalue="+profession
+ ">");
out.println("EMAILID:<inputtype=textname=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.javaimport
java.io.IOException; import
java.io.PrintWriter;
importjavax.servlet.ServletException; import
javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
publicclassRegistrationServletTwoextendsHttpServlet
{
28
public void doPost(HttpServletRequest request, HttpServletResponse
response)
throwsServletException,IOException
{
Stringname=request.getParameter("name");
String password = request.getParameter("password");
Stringprofession=request.getParameter("profession"); String email
= request.getParameter("email");
String cell = request.getParameter("cell");
response.setContentType("text/html"); PrintWriter out =
response.getWriter();
out.println("<html><bodybgcolor=wheat>");
out.println("<center>");
out.println("<h1>REGISTRATIONSUCCESSFUL...................................</h1>");
out.println("</center>");
out.println("</body></html>"); out.close();
}
OUTPUT:
29
RESULT:
2
10
Ex.No.6
ON-LINEEXAMINATIONUSING JSP
QUESTION:
WriteprogramsinJavatocreatethree-tierapplicationsusingJSPand Databases
• Forconductingon-lineexamination.
• Fordisplayingstudentmarklist.Assumethatstudentinformationis available in a
database which has been stored in a database server.
AIM:
To write program in Java to create three-tier applications using JSP and databases
for conducting online examination for displaying student mark list.
PROBLEMDESCRIPTION:
Java:
Javaisawidelyusedprogramminglanguageforcodingweb applications.
Javaisamulti-platform,objectorientedandnetworkcentriclanguage that can be used as
a platform in itself.
JSP
ItstandsforJavaServerPages.
Itisaserver-side technology.
Itisusedforcreatingwebapplication.
Itisusedtocreatedynamicwebcontent.
InthisJSPtagsareusedtoinsertJAVAcodeintoHTMLpages.
ItisanadvancedversionofServletTechnology.
ItisaWebbasedtechnologyhelpsustocreatedynamicand platform-independent
web pages.
Inthis,JavacodecanbeinsertedinHTML/XMLpagesorboth.
JSP is first converted into servlet by JSP container before
processing the client’s request.
PROCEDURE:
StepsforCreatingDataSourceforMicrosoftAccessdrivers
1.GotoControlPanelandSelectAdministrativeToolsandthenselectData Source ODBC icon.
(or)
30
GotoRun(PressWindow+R)andtypeodbcad32.exetogoDataSource ODBC.
2. PressAddButton.
3. ChoosethedriverforMicrosoftAccess. 4.Then,
Press Finish Button.
5. TypeDataSourceNameasExamStudent.
6. ThenPress"SelectButton"andchoosethedatabasefilewhichiscreated already.
7. Then,Press"OK"Buttontocompletetheprocess.
StepsforCreatingDatabaseandtableforthisProgram:
1. CreateMsAccessFileinany Name
2. ThenOpenit.
3. CreatethetableinthenameofStudentTableWithfollowingcolumns Seat_no, Name,
Marks
SchemafortheTable:
Field name DataTypeSeat_no
Number
Name Text
Marks Number
CODING:
//OnlineExam.jsp
<%@pagelanguage="java"import="java.sql.*"%>
<%@pageimport="java.io.*"%>
<%@pageimport="java.util.*"%>
<%
StringSeatNum,Name;
Stringans1,ans2,ans3,ans4,ans5; int
a1,a2,a3,a4,a5; a1=a2=a3=a4=a5=0;
31
Connectionconnect=null;
Statement stmt=null;
ResultSetrs=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;
32
else a5=5;
intTotal=a1+a2+a3+a4+a5;
stmt=connect.createStatement();
Stringquery="INSERTINTOStudentTable("+"Seat_no,Name,Marks"+") VALUES ('" +SeatNum
+ "', '" + Name + "', '"+Total+ "')";
intresult=stmt.executeUpdate(query);
stmt.close();
stmt=connect.createStatement();
query="SELECT*FROMStudentTableWHEREName="+"'"+Name+"'"; rs =
stmt.executeQuery(query);
%>
<html><head><title>StudentMarkList</title></head>
<bodybgcolor=khaki>
<center>
StudentsMarksheet
NameoftheCollege:JAISHRIRAMENGINEERINGCOLLEGE
<tableborder="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:<%=newjava.util.Date().toString()%></td></tr>
<tr><td><b>Signature:X.Y.Z.<b></td></tr>
</table>
<div>
Clickheretogoback
</body>
</html>
<%}else{%>
<html>
<head><title>OnlineExamination</title>
<scriptlanguage="javascript">
functionvalidation(Form_obj)
{
if(Form_obj.Seat_no.value.length==0)
{
alert("Please,filluptheSeatNumber");
Form_obj.Seat_no.focus();
returnfalse;
}
if(Form_obj.Name.value.length==0)
{
alert("Please,filluptheName");
Form_obj.Name.focus();
34
returnfalse;
}
returntrue;
}
</script>
</head>
<bodybgcolor=lightgreen>
<center>
OnlineExamination
</center>
<form action="OnlineExam.jsp" method="post"
name="entry"onSubmit="returnvalidation(this)">
<inputtype="hidden"value="list"name="action">
<hr/>
<table>
<tr>
<td>
SeatNumber:</td>
<td><inputtype="text"name="Seat_no"></td>
</tr>
<tr>
<td>
Name:</td>
<td><inputtype="text"name="Name"size="50"></td>
</tr>
<tr>
<td><b>TotalMarks:5*5=25</b></td>
<td></td><td></td><td></td><td><b>Time:15Min.</b></td>
</tr>
</table>
<hr/>
<b>1.XMLenablesyoutocollectinformationonceandreuseitina variety of
35
ways.</b><br/>
36
<inputtype="radio"name="group1"value="True">True
<inputtype="radio"name="group1"value="False">False<br>
<br/>
<b>2.InModernPCthereisnocache memory.</b><br/>
<inputtype="radio"name="group2"value="True">True
<inputtype="radio"name="group2"value="False">False<br>
<br/>
<b>3.JavaScriptfunctionscannotbeusedtocreatescriptfragments that can be used over
and over again</b><br/>
<inputtype="radio"name="group3"value="True">True
<inputtype="radio"name="group3"value="False">False<br>
<br/>
<b>4.TheDriverManagerclassisusedtoopenaconnectiontoa database via
aJDBC driver.</b><br/>
<inputtype="radio"name="group4"value="True">True
<inputtype="radio"name="group4"value="False">False<br>
<br/>
<b>5.TheJDBCandODBCdoesnotshareacommonparent</b><br/>
<inputtype="radio"name="group5"value="True">True
<inputtype="radio"name="group5"value="False">False<br>
<hr/>
<center>
<inputtype="submit"value="Submit">
<inputtype="reset"value="Clear"><br><br>
</center>
</form>
<%}%>
37
RESULT:
38
Ex.No.7
CREATIONOFXMLDOCUMENT
QUESTION:
Create and save an XML document at the server, which contains 10 users
Information.WriteaProgram,whichtakesuserIdasaninputandreturns the User details by
taking the user information from the XML document
AIM:
PROBLEMDESCRIPTION:
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.
ThestartofXMLmarkup elementsisidentified byeitherthelessthan symbol (), the
apostrophe or single quote (‘) and the double quotation marks (“) are used by XML
for markup.
To use thesespecial charactersascontent within your document, you must use the
corresponding general XML entity.
Elementsrequired:
<form>
<script>
<label>
<input>
<div>
<style>
PROCEDURE:
1. SaveStudentsinformationintheXMLfileonthespecificlocation.
2. CreateandestablishtheserverconnectionbetweenhtmlfileandXML file in the host
39
3. GettheuserIDasinput
4. Displaytheuser’sinformation.
CODING:
index.html
<!DOCTYPEhtml>
<HTML>
<HEAD><TITLE>SearchingforXMLElements</TITLE>
<SCRIPT>
functionreadXMLData()
{
varxmlDocumentObject, id , name , addr, phone, email;
xmlDocumentObject=new XMLHttpRequest();
xmlDocumentObject.open("GET","userlist.xml",false);
xmlDocumentObject.send();
xmlDocumentObject=xmlDocumentObject.responseXML;id=xmlDocume
ntObject.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>SearchUser</H1>
3
10
<inputtype="text"id="myText"value="">
3
11
<input type="BUTTON" VALUE="Get User Details"
ONCLICK="readXMLData()">
<P>
<DIVID="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>
40
<email>[email protected]</email>
40
</userlist>
OUTPUT:
RESULT:
41
42
$comment="";
} else {
$comment=test_input($_POST["comment"]);
}
if(empty($_POST["gender"])){
$genderErr="Genderisrequired";
} else {
$gender=test_input($_POST["gender"]);
}}
functiontest_input($data){
$data=trim($data);
$data=stripslashes($data);
$data=htmlspecialchars($data); return $data;
}
?>
<h2>PHPFormValidationExample</h2>
<p><spanclass="error">*requiredfield</span></p>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Name:<inputtype="text"name="name"value="<?phpecho$name;?>">
<spanclass="error">*<?phpecho$nameErr;?></span>
<br><br>
E-mail:<inputtype="text"name="email"value="<?phpecho$email;?>">
<spanclass="error">*<?phpecho$emailErr;?></span>
<br><br>
Website: <input type="text" name="website" value="<?php echo
$website;?>">
<spanclass="error"><?phpecho$websiteErr;?></span>
<br><br>
Comment:<textareaname="comment"rows="5"cols="40"><?phpecho
$comment;?></textarea>
<br><br>
43
Gender:
<inputtype="radio"name="gender"<?phpif(isset($gender)&&
$gender=="female")echo"checked";?>value="female">Female
<input type="radio" name="gender" <?php if (isset($gender) &&
$gender=="male")
echo"checked";?>value="male">Male
<input type="radio" name="gender" <?php if (isset($gender) &&
$gender=="other")
echo"checked";?>value="other">Other
<spanclass="error">*<?phpecho$genderErr;?></span>
<br><br>
<inputtype="submit"name="submit"value="Submit">
</form>
<?php
echo"<h2>YourInput:</h2>"; echo
$name;
echo "<br>"; echo
$email; echo
"<br>"; echo
$website; echo
"<br>";
echo$comment;
echo "<br>"; echo
$gender;
?>
</body>
</html>
44
OUTPUT:
RESULT:
45
46
67