Nothing Special   »   [go: up one dir, main page]

Program:1

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 39

WPSLAB

PROGRAM:1 PROGRAM USING BASIC HTML TAGS

<!--USING BASIC HTML TAGS------->

<html>
<head>
<title>Basic html tags</title>
</head>
<body >
<font color="brown" font face="arial helvetica ">
<h1 align="center"><u>!!WELCOME!!</u></h1>
<h2 align="center">!!WELCOME!!</h2>
<h3 align="center">!!WELCOME!!</h3>
<h4 align="center">!!WELCOME!!</h4>
<h5 align="center">!!WELCOME!!</h5>
<h6 align="center">!!WELCOME!!</h6>
</font>
<font color="green" size=10>
<p>This is a <b><i>sample</i></b> of web page <br/>using basic
html tags like<br/>
</font>
<font size=6 color="blue">
<pre>headings,font <sub>colors,types,sizes
</sub>,alignments,subscripts,pretag</pre></p>
</font>
</body>
</html>

OUTPUT:

1
WPSLAB

PROGRAM:2 FORMATTING TAGS


<html>
<head>
<title>Formatting tags</title>
</head>
<body>
<h3 align="center">Formatting tags</h3>
<b>This text is bold</b><br/>
<big> This text is big </big><br/>
<i> This text is italic </i><br/>
<small> This text is small </small> </br>
This text contains <sub> subscript </sub> </br>
This text contains <sup> superscript </sup>
</body>
</html>

OUTPUT:

2
WPSLAB

PROGRAM:3 PROGRAM USING LISTS


<html>
<head>
<title>Lists</title>
<style type=text/css>
p{color:teal}
</style>
</head>
<body>
<h1 align="center"><font color="purple"><u>USING LISTS</u></font></h1>
<h2><font color="darkgreen"><b>THE SEVEN WONDERS OF WORLD</b></font></h2>
<font color="brown">
<li><h3>Chichen Itza</h3>
<ul>
<li><h4><p>located in Yucatin,<i>MEXICO</i></p></h4></li>
<li>for image<a href="chichenitza.jpg">Click here</a></li>
</ul>
<li><h3>Taj Mahal</h3></li>
<ul>
<li><h4><p>located in Agra,<i>INDIA</i></p></h4></li>
<li>for image<a href="TAJ.jpg">Click here</a></li>
</ul>
<li><h3>The Great wall of China</h3></li>
<ul>
<li><h4><p>located in <i>CHINA</i></p></h4></li>
<li>for image<a href="greatwall.jpg">Click here</a></li>
</ul>
<li><h3>Colosseum</h3></li>
<ul>
<li><h4><p>located in Rome,<i>ITALY</i></p></h4></li>
<li>for image<a href="colosseum.jpg">Click here</a></li>
</ul>
<li><h3>Petra</h3></li>
<ul>
<li><h4><p>located in <i>JORDAN</i></p></h4></li>
<li>for image<a href="petra.jpg">Click here</a></li>
</ul>
<li><h3>Machu picchu</h3></li>
<ul>

3
WPSLAB

<li><h4><p>located in cuzco,<i>PERU</i></p></h4></li>
<li>for image<a href="machupicchu.jpg">Click here</a></li>
</ul>
<li><h3>Christ The Redeemer</h3></li>
<ul>
<li><h4><p>located in Rio De Janerio,<i>BRAZIL</i></p></h4></li>
<li>for image<a href="christredeemer.jpg">Click here</a></li>
</ul>
</font>
</ol>
</body>
</html>

OUTPUT:

4
WPSLAB

PROGRAM:4 LINKS
<html>
<head>
<title>LINKS </title>
</head>
<body>
<h1 align="center">Links</h1>
<ol>
<li><h2>Linking other html documents</h2></li>
<ul>
<li><a href="sample.html">Basic tags</a></li>
<li><a href="images.html">Displaying images</a></li>
</ul>
<li><h2>Linking images</h2></li>
<a href="sample.html">
<img src="petra.jpg" width=100 height=100>Petra</a><br/>
<a href="images.html">
<img src="Taj.jpg" width=100 height=100>TAJ</a>
</ol>
</body>
</html>

OUTPUT:

5
WPSLAB

PROGRAM:5 PROGRAM TO ILLUSTRATE IMAGES

<html>
<head>
<title>Images</title>
</head>
<body>
<h2 align="center"><i>Displaying images</i></h2>
<h3>1.TAJ</h3><center>
<img src="Taj.jpg" width=500 height=250></center>
<h3>2.Machupichu</h3><center>
<img src="machupicchu.jpg" width=500 height=250></center>
</body>
</html>

OUTPUT:

6
WPSLAB

PROGRAM:6 PROGRAM TO DEMONSTRATE FRAMES


<html>
<head>
<title>Frames</title>
</head>
<frameset cols="40%,60%">
<frame src="lists.html">
<frameset rows="30%,70%">
<frame src="colosseum.jpg">
<frame src="images.html">
</frameset>
</frameset>
</html>

7
WPSLAB

OUTPUT:

PROGRAM:7 Formatted text using tables


<html>
<head> <title> formatting text using tables</title>
<table border=10 width=100%>
<tr>
<td> <font color=purple font size=10> CBIT </font> </td>
<td>
<img src="CBIT.png" width=100 height=100></td>
</tr>
<tr>
<td> <font color=blue> CSE </font> </td>
<td> <font color=blue> ECE </FONT> </TD>
</tr>
<tr>
<td> <table border=1 width=50% bgcolor=lavender cellpadding=20

8
WPSLAB

cellspacing=15>
<tr> <td> BRANCH </td>
<td> ROLL NO </td>
</tr>
<tr> <td> CSE </td>
<td> 8063</td>
</tr>
<tr>
<td> ECE </td>
<td>4012 </td>
</tr>
</table>
</td>
<td> DEPARTMENTS AND ROLLNO.s OF STUDENTS </td>
</tr>
</table>
</html>

OUTPUT:

9
WPSLAB

10
WPSLAB

PROGRAM:8 FORMS
<html>
<head><title>Form</title>
</head>
<body>
<table border=0 width=100% cellspacing=5 cellpadding=10>
<tr>
<td>
<table border=0 cellspacing=5 cellpadding=10>
<tr>
<td><u><b>YAHOO!</b></u></td>
</tr>
<tr>
<td>Username</td><td><input type=text name=Username></td>
</tr>
<tr>
<td>Password</td><td><input type=password ></td>
</tr>
<tr>
<td><input type=checkbox >
Remember password ?</td>
</tr>
<tr>
<td><input type=button name=login value=LOGIN>
<input type=button name=cancel value=cancel ></td>
</tr>
</table>
</td>
<td>
<table border=0 cellspacing=5 cellpadding=10>
<tr>
<td><b><u>GOOGLE</u></b></td>
</tr>
<tr>
<td>Username</td><td><input type=text name=Username></td>
</tr>
<tr>
<td>Password</td><td><input type=password ></td>
</tr>

11
WPSLAB

<tr>
<td><input type=checkbox >
Remember password ?</td>
</tr>
<tr>
<td><input type=button name=login value=LOGIN>
<input type=button name=cancel value=cancel ></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>

OUTPUT:

12
WPSLAB

PROGRAM:9 Program to perform arithmetic operations using Javascript


<!---arithmetic operations using javascript-->

<html>
<head><title>Arithmetic operations</title>
<script type=text/javascript>
function addition(a,b)
{
var a,b,c;
a=parseInt(document.fm.fa.value);
b=parseInt(document.fm.fb.value);
c=a+b;
document.fm.fc.value=c;
}
function subtraction(a,b)
{
var a,b,c;
a=parseInt(document.fm.fa.value);
b=parseInt(document.fm.fb.value);
c=a-b;
document.fm.fc.value=c;
}
function multiplication(a,b)
{
var a,b,c;
a=parseInt(document.fm.fa.value);
b=parseInt(document.fm.fb.value);
c=a*b;
document.fm.fc.value=c;
}
function division(a,b)
{
var a,b,c;
a=parseInt(document.fm.fa.value);
b=parseInt(document.fm.fb.value);
c=a/b;
document.fm.fc.value=c;
}
</script>

13
WPSLAB

</head>

<body>
<form name=fm>
<h3>a</h3>
<input type=text name=fa>
<h3>b</h3>
<input type=text name=fb><br/>
<h3>c</h3>
<input type=text name=fc><br/><br/>
<input type=button value=add > <input type=button value=sub > <input type=button value=mul > <input type=button value=div > </form>
</body>
</html>

OUTPUT:

14
WPSLAB

PROGRAM:10 PROGRAM TO VALIDATE WEBADDRESS, EMAIL USING JAVASCRIPT


<html>
<head><title>test memail id and web</title></head>
<script type="text/javascript">
function testMailIDandWeb()
{
var a,b;
a=document.test.aval.value;
b=document.test.bval.value;
var p=a.search(/\w\@\w+\.com/);
var q=b.search(/www\.\w+\.\w+/);
if(p>=0)
{
if(q>=0)
document.writeln("VALID MAIL and WEB");
else
document.writeln("INVALID web");
}
else
{
if(q>=0)
document.writeln("INVALID mail");
else
document.writeln("INVALID MAIL ID AND WEB");
}
}
</script></head>
<body>
<form name="test">
<h3>ENTER MAIL ID:</h3>
<input type=text name=aval><br/>
<h3>ENTER WEB ADDRESS</h3>
<input type=text name=bval><br/>
<input type=button value="TEST" ></form>
</body>
</html>

15
WPSLAB

OUTPUT:

16
WPSLAB

PROGRAM:11 PASSWORDCHECK USING EVENTHANDLING


<!---pswd.html--->

<html>
<head>
<title>validation</title>
<script type="text/javascript" src="pswdcheck.js">
</script>
</head>
<body>
<h1>password check</h1>
<form id="passwordform" action=" ">
<p>enter password</p>
<input type="password" id="first">
<p>Verify password</p>
<input type="password" id="second"><br/>
<input type=reset value=reset>
<input type=button value=submit > </form>
<script type="text/javascript" src="regevent.js">
</script>
</body>
</html>

<!---pswd.js--- >

function passwordcheck()
{
var >var two=document.getElementById("second");
if(one.value =="")
{
alert("You havenot enter the password\n"+"Please enter it");
one.focus();
return false;
}

17
WPSLAB

if(one.value!=two.value)
{
alert(" Passwords donot match\n"+"Enter both fields again");
one.focus();
one.select();
return false;
}
else
return true;
}

<!-----regevent.js- ->

document.getElmentById("second"). >document.getElementById("passwordform").>

OUTPUT:

18
WPSLAB

PROGRAM:12 DHTML positioning


I. ABSOLUTE POSITIONING:

<html>
<head><title>Absolute positioning</title>
<style type="text/css">
.regtext{font-family:arial;font-size:30pt;width=600px;
position:absolute;top:125px;left:100px; }
.abstext{position:absolute;Top:10px;left:50px;
font-family:italic;letter-spacing:lem;font-size:36pt;
color:teal;width:400px;}
</style>
</head>
<body>
<div class="regtext">
Dynamic XHTML is not a markup language.It is a collection of technologies that allows
dynamic changes to documents described with XHTML.
<span class="abstext">
This is an example for ABSOLUTE positioning
</span>
</div>
</body>
</html>

OUTPUT:

19
WPSLAB

II. RELATIVE POSITIONING:

<html>
<head><title>Relative positioning</title></head>
<body style="font-family:times;font-size=24pt;">
<p>
This is an example for illustrating<span style="position:relative;Top:10px;
font-family:times;font-style:italic;font-size:24pt;
color:red;">
RELATIVE POSITIONING</span> of elements.
</p>
<body>
</html>

OUTPUT:

20
WPSLAB

PROGRAM:13 DHTML CHANGING COLORS

<!----DHTMLcolor.html----->

<html>
<head><title>Dynamic colors</title>
<script type="text/javascript" src="dyncolors.js">
</script>
</head>
<body>
<p style="font-family:times;font-style:italic;font-size:24pt">
This small page illustrates dynamic setting of the foreground and background colors for a
document
</p>
<form action=" ">
<p>
<label>Background color

21
WPSLAB

<input type="text" name="background" size="10"


></label>
<label>Foreground color
<input type="text" name="foreground" size="10"
></label>
<br/>
</p>
</form>
</body>
</html>

<!---dyncolors.js --- >

function setColor(where,newColor)
{
if(where=="background")
document.body.style.backgroundColor=newColor;
else
document.body.style.color=newColor;
}

OUTPUT:

22
WPSLAB

PROGRAM:14 WELL FORMED AND VALID XML DOCUMENT

<!----Well formed Xml---- >

23
WPSLAB

<?xml version="1.0" ?>


<subjectlist>
<sub>
<title>WPS</title>
<reference>WEB programming by Sebesta</reference>
</sub>
<sub>
<title>OOSD</title>
<reference>UML user guide by GRADY BOOCH</reference>
</sub>
<sub>
<title>ALGORITHMS</title>
<reference>Computer algorithms by sahni</reference>
</sub>
</subjectlist>

OUTPUT:

<!---VALID XML ------ >

Using internal DTD:

<?xml version="1.0" ?>

24
WPSLAB

<!DOCTYPE ORGANISATION [
<!ELEMENT ORGANISATION (EMPLOYEE+)>
<!ELEMENT EMPLOYEE (EMPID?,EMPNAME+,EMPDESIGNATION*)>
<!ELEMENT EMPID (#PCDATA) >
<!ELEMENT EMPNAME (#PCDATA)>
<!ELEMENT EMPDESIGNATION (#PCDATA)>
<!ATTLIST PLACE NAME CDATA #REQUIRED>
]>
<ORGANISATION>
<EMPLOYEE>
<EMPID>555</EMPID>
<EMPNAME>CLARK</EMPNAME>
<EMPDESIGNATION>SE</EMPDESIGNATION>
<PLACE NAME = "HYD" >AP</PLACE>
</EMPLOYEE>
<EMPLOYEE>
<EMPID>666</EMPID>
<EMPNAME>ROBBIN</EMPNAME>
<EMPDESIGNATION>TE</EMPDESIGNATION>
<PLACE NAME = "NEWYORK">US</PLACE>
</EMPLOYEE>
</ORGANISATION>

EXAMPLE2:

<!---External DTD------- >

<?xml version="1.0" ?>


<!DOCTYPE ORGANISATION SYSTEM "Employee.dtd">
<ORGANISATION>
<EMPLOYEE>
<EMPID>555</EMPID>
<EMPNAME>CLARK</EMPNAME>
<EMPDESIGNATION>SE</EMPDESIGNATION>
<PLACE NAME = "HYD" >AP</PLACE>
</EMPLOYEE>
<EMPLOYEE>
<EMPID>666</EMPID>
<EMPNAME>ROB</EMPNAME>
<EMPDESIGNATION>TE</EMPDESIGNATION>
<PLACE NAME = "NEWYORK">US</PLACE>
</EMPLOYEE>
</ORGANISATION>

25
WPSLAB

<!----------Employee.dtd--- >

<!ELEMENT ORGANISATION (EMPLOYEE+)>


<!ELEMENT EMPLOYEE (EMPID?,EMPNAME+,EMPDESIGNATION*)>
<!ELEMENT EMPID (#PCDATA) >
<!ELEMENT EMPNAME (#PCDATA)>
<!ELEMENT EMPDESIGNATION (#PCDATA)>
<!ATTLIST PLACE NAME CDATA #REQUIRED>

OUTPUT:

PROGRAM:15 XSLT

<!---xml document--->

26
WPSLAB

<?xml version="1.0" ?>


<?xml-stylesheet type="text/xsl" href="xslt.xsl"?>
<subject>
<sub>
<title>WPS</title>
<reference>WEB programming by Sebesta</reference>
</sub>
<sub>
<title>OOSD</title>
<reference>UML user guide by GRADY
BOOCH</reference>
</sub>
<sub>
<title>ALGORITHMS</title>
<reference>Computer algorithms by sahni</reference>
</sub>
<sub>
<title>PPL</title>
<reference>PPL by RaviSethi</reference>
</sub>
</subject>

The following XSLT stylesheet processes previous XML document


<!---------xslt.xsl--- >

<?xml version="1.0" ?>


<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>SUBJECT DETAILS</h2>
<table border="1">
<tr bgcolor="lavender">
<th>TITLE</th>
<th>REFERENCE</th>
</tr>
<xsl:for-each select="subject/sub">
<tr>
<td><xsl:value-of select="title" /></td>
<td><xsl:value-of select="reference" /> </td>

27
WPSLAB

</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

OUTPUT:

PROGRAM:16 Retrieving information using ACTIVEXOBJECT(XMLDOM)

<html>
<head><title> XML DOM</title>

28
WPSLAB

</head>
<body>
<script type="text/javascript">
function sublistinfo()
{
xmlDoc= new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.load("sublist.xml");
x=xmlDoc.getElementsByTagName("sub")[0];
document.writeln("SUBJECT DETAILS"+"<br/>");
document.writeln("TITLE:"+x.firstChild.childNodes[0].nodeValue+"<br/>");
document.writeln("REFERENCE:"+x.lastChild.childNodes[0].nodeValue);
document.writeln("<br/>"+"NEXT SUBJECT DETAILS "+"<br/>");
document.writeln("TITLE:"+x.nextSibling.firstChild.childNodes[0].nodeValue+"<br/>");
document.writeln("REFERENCE:"+x.nextSibling.lastChild.childNodes[0].nodeValue);
}
</script>
<form>
<input type="button" name=click value=click ></body>
</html>

<!---sublist.xml--->
<?xml version="1.0" ?>
<subjectlist>
<sub>
<title>WPS</title>
<reference>WEB programming by Sebesta</reference>
</sub>
<sub>
<title>OOSD</title>
<reference>UML user guide by GRADY BOOCH</reference>
</sub>
<sub>
<title>ALGORITHMS</title>
<reference>Computer algorithms by sahni</reference>
</sub>
<sub>
<title>PPL</title>
<reference>PPL by RaviSethi</reference>

29
WPSLAB

</sub>
</subjectlist>

OUTPUT:

PROGRAM:17 CREATING A TABLE USING JDBC

/*Program to create a table*/

30
WPSLAB

import java.sql.*;
public class CreateStudent
{
public static void main(String[] args)
{
Connection con = null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con =DriverManager.getConnection("jdbc:odbc:STUDENTDB");
// Creating a database table
Statement stmt = con.createStatement();
int count = stmt.executeUpdate(
"CREATE TABLE Studenttable (STID INT, STUname VARCHAR(20))");
System.out.println("Table created.");
stmt.close();
con.close();
}
catch(IOException e)
{
System.out.println(e.toString());
}
catch(ClassNotFoundException e)
{
System.out.println("CLASS NOT FOUND");
}
}
}

OUTPUT:

31
WPSLAB

32
WPSLAB

PROGRAM:18 INSERTION INTO A TABLE USING JDBC

//program to insert rows

import java.sql.*;
public class InsertRows
{
public static void main(String [] args)
{
Connection con = null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:STUDENTDB");
Statement sta = con.createStatement();
int count = 0;
int c ;
c= sta.executeUpdate("INSERT INTO Studenttable (STID, STUname) VALUES(1,'Aparna')");
count = count + c;
c = sta.executeUpdate("INSERT INTO Studenttable (STID, STUname) VALUES (2,'Anusha')");
count = count + c;
c = sta.executeUpdate("INSERT INTO Studenttable (STID, STUname) VALUES (3,'Anjali')");
count = count + c;
System.out.println("Number of rows inserted: "+count);
sta.close();
con.close();
}
catch(IOException e)
{
System.out.println(e.toString());
}
catch(ClassNotFoundException e)
{
System.out.println("CLASS NOT FOUND");
}
}
}

33
WPSLAB

OUTPUT:

34
WPSLAB

PROGRAM:19 Retrieving information using PreparedStatement and ResultSet

//USING PREPARED STATEMENT FOR RETREIVING DATA

import java.sql.*;
import java.io.*;

public class RetreiveData


{
public static void main(String[] args)
{
Connection con = null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:STUDENTDB");
PreparedStatement stmt =con.prepareStatement("SELECT STUname,STID FROM
studenttable WHERE STID=? ");
System.out.println("Enter StudentId");
InputStreamReader in= new InputStreamReader(System.in);
BufferedReader bin= new BufferedReader(in);
String str=bin.readLine();
int STID=Integer.parseInt(str);
stmt.setInt(1,STID);
ResultSet res=stmt.executeQuery();
// getting the data back
while (res.next())
{
System.out.println("Studentname="+res.getString(1));
}
res.close();
stmt.close();
con.close();
}
catch(IOException e)
{
System.out.println(e.toString());
}
catch(ClassNotFoundException e)
{

35
WPSLAB

System.out.println("CLASS NOT FOUND");


}
catch(SQLException e)
{
System.out.println(e.toString());
}
}
}

OUTPUT:

36
WPSLAB

PROGRAM 20 BASIC SERVLET EXAMPLE

import java.io.*;
import javax.servlet.*;
public class BasicServlet extends GenericServlet
{
public void service(ServletRequest req, ServletResponse res) throws ServletException,
IOException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("<html>");
out.println("<head><title>Basic servlet example</title></head>");
out.println("<body >");
out.println("<h1 align=center> K.APARNA</h1>");
out.println("<h2 align=center>02078063</h2>");
out.println("</body>");
out.println("</html>");

}
}

OUTPUT:

37
WPSLAB

PROGRAM:21 SERVLET FORM PROGRAM

<html>
<head><title>Form</title></head>
<body>
<form name="form1" method=post action="http://localhost:8080/servlets-
examples/servlet/FormExample">
<p>Studentname</p>
<input type=text name=N>
<p>Rollno</p>
<input type=text name=R>
<p>Branch</p>
<input type=text name=B>
<input type=submit value=submit>
<input type=reset value =reset>
</form>
<body>
</html>

<!-----FormExample.java---->

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

public class FormExample extends HttpServlet {


public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String a=request.getParameter("N");
String b=request.getParameter("R");
String c=request.getParameter("B");
out.println("<html><body>");
out.println("<h3>U have just entered the following<h3><br/>");
out.println("Studentname:"+a+"<br/>");
out.println("Rollno:"+b+"<br/>");

38
WPSLAB

out.println("Branch:"+c+"<br/>");
}
}

OUTPUT:

When all the fields are entered and submitted,the following HTML page displays

39

You might also like