You are on page 1of 42

I.T.

S ENGINEERING
COLLEGE
SESSION: - 2010-2011
ODD SEMESTER

IWT LAB FILE

SUBMITTED TO: -
SUBMITTED BY:-
S.N NAME OF PROGRAM DATE REMAR
O KS

1. Display Resume By Using


HTML

2. Display Train Time Table By


Using HTML

3. Yahoo Sign Up Page

4. DB Insertion of 3 Fields
5. XML File for Student
6. Servlet to Display Current
Date and Time
7. DB Connection to
MySQL(JDBC)

8. DB Insertion, Deletion and


Updation in MySQL(JDBC)
Resume
<html>
<head>
<title>Resume</title>
</head>
<body>
<h3 align="center"><u>Resume</u></h3><br/><br/>
<table width="100%">
<tr style="background:black" ><td align="center"><font color="white"
align="center">Personal Details</font></td></tr>
</table>

<table align="center" width="100%" ><b>

<tr>
<td>&nbsp;Name:</td><td>Rahul Prasad </td>
</tr>
<tr>
<td>&nbsp; Address:</td><td> Faculty center, ALTTC, Rajnagar, GZB
</td>
</tr>
<tr>
<td>&nbsp;Age:</td><td>20 yrs</td>
</tr>
<tr>
<td>&nbsp;Degree:</td><td>B.Tech Computer Science</td>
</tr>
<tr>
<td>&nbsp;Objective:</td><td>To excel in the field of Computer
engineering in a growth-oriented organization, that enables me to fully utilize
my technical skills.</td>
</tr>
</b></table>
<br/><br/><br/>
<hr/>
<table width="100%">
<tr style="background:black" ><td align="center"><font color="white"
align="center">Education</font></td></tr>
</table>
<br/>
<table align= center border=1>
<tr style="background:maroon"><td><font
color="white">&nbsp;Qualification</font></td> <td><font
color="white">&nbsp;Institute</font></td> <td><font
color="white">&nbsp;Board/University</font></td> <td><font
color="white">&nbsp;Year</font></td> <td><font
color="white">&nbsp;Percentage/Marks</font></td> </tr>
<tr>
<td>&nbsp;B.Tech (3rd Year)</td><td>&nbsp;I.T.S Engg. College,
Greater Noida</td><td>&nbsp;U.P. Technical
University</td><td>&nbsp;2009</td><td>&nbsp; </td>
</tr>
<tr>
<td>&nbsp;B.Tech (2nd Year)</td><td>&nbsp;I.T.S Engg. College,
Greater Noida</td><td>&nbsp;U.P. Technical
University</td><td>&nbsp;2008</td><td>&nbsp; </td>
</tr>
<tr>
<td>&nbsp;B.Tech (1st Year)</td><td>&nbsp;I.T.S Engg. College,
Greater Noida</td><td>&nbsp;U.P. Technical
University</td><td>&nbsp;2007</td><td>&nbsp; td>
</tr>
<tr>
<td>&nbsp;XII</td><td>&nbsp; R.K.I. Ghaziabad

</td><td>&nbsp;C.B.S.E</td><td>&nbsp;2006</td><td>&nbsp; </td>

</tr>
<tr>
<td>&nbsp;X</td><td>&nbsp; R.K.I. Ghaziabad

</td><td>&nbsp;C.B.S.E</td><td>&nbsp;2004</td><td>&nbsp; </td>

</tr>
</table>
<br/><br/>
<hr/>
<table width="100%">
<tr style="background:black" ><td align="center"><font color="white"
align="center">Achievements</font></td></tr>
</table>
<br/><br/>
<table width="100%">
<tr>
<td>&nbsp;1. . Member of Computer Society of India(C.S.I )</td>
</tr>
<tr>
<td>&nbsp;2. Participated in various Academic activities and
various other competitions at school & college </td>
</tr>
</table>
<br/><br/>
<hr/>

<table width="100%">
<tr style="background:black" ><td align="center"><font color="white"
align="center">Additional Skills</font></td></tr>
</table>
<br/><br/>
Programming skills known:
<table width="100%">
<tr>
<td>&nbsp;1. C,C++, </td>
</tr>
<tr>
<td>&nbsp;2. Matlab 7.0</td>
</tr>
<tr>
<td>&nbsp;3. Visual Studio 6.0,SQL 2003</td>
</tr>
<tr>
<td>&nbsp;5. Micrsoft Powerpoint 2003,Access 2003,Word 2003</td>
</tr>
</table>
<br/><br/>
<hr/>
<table width="100%">
<tr style="background:black" ><td align="center"><font color="white"
align="center">Extra Curricular Activities</font></td></tr>
</table>
<br/><br/>
<table width="100%">
<tr>
<td>&nbsp;1. Member of Computer Society of India(C.S.I)</td>
</tr>
<tr>
<td>&nbsp;2. Member of BRILLANZ-Computer Society of I.T.S Engg.
College, Greater Noida</td>
</tr>
<tr>
<td>&nbsp;3. Playing Badminton</td>
</tr>
<tr>
<td>&nbsp;4. Reading Books</td>
</tr>
<tr>
<td>&nbsp;5. Computer Gaming</td>
</tr>
</table>
<br/><br/>
<hr/>
</table>
</body>
</html>
Resume
Personal Details
Name: Rahul Prasad

Address: Faculty center, ALTTC, Rajnagar, GZB

Age: 20 yrs

Degree: B.Tech Computer Science

Intend to build a career with corporate with


committed and dedicated people, which will help me
Objective: to explore my-self fully and release my ultimate
potential and hence contribute in growth of
organization

Educational Qualification
Qualification Institute Board/University Year Percentage/Marks

B.Tech (3rd I.T.S Engg. College, U.P. Technical 201


Year) Greater Noida University 0
68%

B.Tech (2nd I.T.S Engg. College, U.P. Technical 200


Year) Greater Noida University 9
62.80%

B.Tech (1st I.T.S Engg. College, U.P. Technical 200


Year) Greater Noida University 8
68%

R.K.I. Ghaziabad
200
XII C.B.S.E
6
65%

200
X R.K.I. Ghaziabad C.B.S.E
4
65%
Achievements
1. Member of C.S.I(Computer Society of India)
2. Participated in various Academic activities and
various other competitions at school & college.

Additional Skills
Programming skills known:
1. C,C++

2. Matlab 7.0

3. Visual Studio 6.0

4. Microsoft PowerPoint 2003,Access 2003,Word 2003

Extra Curricular Activities


1. Member of Computer Society of India(C.S.I)

2. Member of BRILLANZ-Computer Society of I.T.S Engg. College, Greater Noida

3. Playing Badminton

4. Reading Books

5. Computer Gaming

Train Time- Table


<html>

<head>
<title>Train Schedule</title>
</head>
<body>
<h3 align="center">Train Schedule</h3>
<table border=1 align="center">
<tr style="background-color:#6CF">
<td align="center" rowspan="2" colspan="2">&nbsp;Train</td>
<td align="center" rowspan="2" colspan="2">&nbsp;Name</td>
<td align="center" rowspan="2" colspan="2">&nbsp;Source</td>
<td align="center" rowspan="2"
colspan="2">&nbsp;Destination</td>
<td colspan=2 align="center">Time<td align="center" rowspan="2"
colspan="2" >&nbsp;Fare</td><tr style="background-
color:#6CF"><td>&nbsp;Arrival</td><td>&nbsp;Departure</td></td>
</tr>
<tr>
<td align="center" rowspan="2" colspan="2">&nbsp;1212</td>
<td align="center" rowspan="2" colspan="2">&nbsp;Jo Bole So Nihaal
Express</td>
<td align="center" rowspan="2" colspan="2">&nbsp;Amritsar</td>
<td align="center" rowspan="2" colspan="2">&nbsp;Lahore</td>
<td align="center" rowspan="2" >&nbsp;12:00 pm</td>
<td align="center" rowspan="2" >&nbsp;12:10 pm</td>
<td align="center" rowspan="2" colspan="2">&nbsp;Rs
120</td><tr></tr>
</tr>
<tr>
<td align="center" rowspan="2" colspan="2">&nbsp;6666</td>
<td align="center" rowspan="2" colspan="2">&nbsp;Satriakaal
Express</td>
<td align="center" rowspan="2" colspan="2">&nbsp;Lahore</td>
<td align="center" rowspan="2" colspan="2">&nbsp;Amritsar</td>
<td align="center" rowspan="2" >&nbsp;06:00 pm</td>
<td align="center" rowspan="2" >&nbsp;06:10 pm</td>
<td align="center" rowspan="2" colspan="2">&nbsp;Rs
420</td><tr></tr>
</tr>
</table></body></html>

Train Schedule
Time
Trai Destinati
Name Source Fare
n on Departu
Arrival
re

121 Jo Bole So Nihaal Amrits 12:00 12:10 Rs


Lahore
2 Express ar pm pm 120

666 06:00 06:10 Rs


Satriakaal Express Lahore Amritsar
6 pm pm 420

DB Insertion of 3 Fields
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>

<%
class DBConnect
{
String user;
String pass;
String dbname;
String url;
Connection conn;
Statement stmt;
ResultSet rs=null;
ResultSetMetaData rsm=null;
boolean status=true;
/** Creates a new instance of DBConnect */
public void CloseConn()
{
if(conn!=null)
{
try
{
conn.close();
System.out.println("Connection Terminated");
}
catch(Exception e1)
{
e1.toString();
}
}
}
public DBConnect(String tuser,String tpass,String tdbname)
{
user=tuser;
pass=tpass;
dbname=tdbname;
url="jdbc:mysql://localhost/"+dbname;
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn=DriverManager.getConnection(url,user,pass);
stmt=conn.createStatement();
}
catch(Exception e)
{
status=false;
}
}
}

class QueryExecute
{
ResultSet rs=null;
ResultSetMetaData rsm=null;
boolean status=true;
String querytype=null;
int count,row,col;
/** Creates a new instance of QueryExecute */
public QueryExecute(DBConnect db,String query)
{
try
{
db.stmt.executeQuery(query);
querytype="retrieve";
}
catch(Exception e)
{
try
{
count=db.stmt.executeUpdate(query);
System.out.println(count);
querytype="insert";
}
catch(Exception e1)
{
status=false;
}
}
if(querytype.equals("retrieve")==true)
{
try
{
rs=db.stmt.getResultSet();
rsm=rs.getMetaData();
rs.last();
row=rs.getRow();
col=rsm.getColumnCount();
if(row<1 || col<1)
{
status=false;
}
else
{
rs.first();
rs.previous();
}
}
catch(Exception e)
{
status=false;
}
}
}
}
String name=null,cell=null,email=null;
name=request.getParameter("name");
cell=request.getParameter("cell");
email=request.getParameter("email");
if(name!=null && cell!=null && email!=null)
{
DBConnect db = new DBConnect("root","netwin","mobile");
QueryExecute qe = new QueryExecute(db,"Insert into dbinsert
(name,cell,email) values('"+name+"','"+cell+"','"+email+"')");
if(qe.status==true)
{
%>
<script type="text/javascript">
alert('Field(s) Inserted');
</script>
<%
}
}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>DB Insertion</title>
<script type="text/javascript">
function Validate()
{
var nam=document.getElementById('name').value;
var cel=document.getElementById('cell').value;
var emai=document.getElementById('email').value;
if(nam=='' || cel=='' || emai=='')
{
alert('Field(s) Empty');
return false;
}
else
{
if(cel.length!=10)
{
alert('Cell Value Length Incorrect');
return false;
}
else
{
for(var i=0;i<cel.length;i++)
{
if(cel.charAt(i)<'0' || cel.charAt(i)>'9')
{
alert('Invalid No');
return false;
}
}
var count1=0,count2=0;
for(i=0;i<emai.length;i++)
{
if(emai.charAt(i)=='@')
{
count1++;
}
if(emai.charAt(i)=='.')
{
count2++;
}
}
if(count1!=1 || count2!=1)
{
alert('Invalid Email');
return false;
}
else
{
alert('All Information Correct');
document.frm.action='DBInsert.jsp';
document.frm.submit();
return true;
}
}
}
}
</script>
</head>
<body onload="document.getElementById('name').focus()"><form
name="frm">

<h1>Application</h1>

<table border="0">
<tr>
<td>Name:</td>
<td><input type="text" name="name" id="name" value=""/></td>
</tr>
<tr>
<td>Cell No:</td>
<td><input type="text" name="cell" id="cell" value=""
maxlength="10"/></td>
</tr>
<tr>
<td>Email Id:</td>
<td><input type="text" name="email" id="email" value=""/></td>
</tr>
<tr>
<td align="center" colspan="2"><input type="button" value="Insert"
onclick="Validate()"/></td>
</tr>
</table>

</form></body>
</html>

OUTPUT:
Web Form:

DataBase:

DB Connection to MySQL
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page import="java.sql.*" %>
<%@page import="javax.swing.*" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"


"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>DBMS</title>
<%
class DBConnect
{
String user;
String pass;
String dbname;
String url;
Connection conn;
Statement stmt;
ResultSet rs=null;
ResultSetMetaData rsm=null;
boolean status=true;
/** Creates a new instance of DBConnect */
public void CloseConn()
{
if(conn!=null)
{
try
{
conn.close();
System.out.println("Connection Terminated");
}
catch(Exception e1)
{
e1.toString();
}
}
}
public DBConnect(String tuser,String tpass,String tdbname)
{
user=tuser;
pass=tpass;
dbname=tdbname;
url="jdbc:mysql://localhost/"+dbname;
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn=DriverManager.getConnection(url,user,pass);
stmt=conn.createStatement();
}
catch(Exception e)
{
status=false;
}
}
}

class QueryExecute
{
ResultSet rs=null;
ResultSetMetaData rsm=null;
boolean status=true;
String querytype=null;
String error=null;
int count,row,col;
/** Creates a new instance of QueryExecute */
public QueryExecute(DBConnect db,String query)
{
try
{
db.stmt.executeQuery(query);
querytype="retrieve";
}
catch(Exception e)
{
try
{
count=db.stmt.executeUpdate(query);
System.out.println(count);
querytype="insert";
}
catch(Exception e1)
{
status=false;
error=new String(e1.toString());
}
}
if(querytype.equals("retrieve")==true)
{
try
{
rs=db.stmt.getResultSet();
rsm=rs.getMetaData();
rs.last();
row=rs.getRow();
col=rsm.getColumnCount();
if(row<1 || col<1)
{
status=false;
}
else
{
rs.first();
rs.previous();
}
}
catch(Exception e)
{
status=false;
error=new String(e.toString());
}
}
}
}

%>
</head>
<body onload="OnLoad()"><form name="frm" id="frm">
<h1>DBMS</h1>
<table>
<tr><td>UserName:</td><td><input type="text" name="user"
id="user"/></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass"
id="pass"/></td></tr>
<tr><td colspan="2" align="center"><input type="button"
value="Connect" name="connectionbox" id="connectionbox"
onclick="Connect()"/></td></tr>
</table>
<%
QueryExecute qe=null;
String username=null,password=null;
username=request.getParameter("user");
password=request.getParameter("pass");
if(username!=null && password!=null)
{
%>
<script type="text/javascript">
document.getElementById('user').value="<%=username%>";
document.getElementById('pass').value="<%=password%>";
</script>
<%
DBConnect db = new DBConnect(username,password,"");
if(db.status==false)
{
%>
<script type="text/javascript">
alert('Connection to DataBase Failed');
</script>
<%
}
else
{
qe=new QueryExecute(db,"Show Databases");
if(qe.status==false)
{
%>
<br/><hr/><br/>
<h1>No DataBase Retrieved</h1>
<br/><hr/><br/>
<%
}
if(qe.status==true)
{
%>
<br/><hr/><br/><h1>Connection to DataBase Established</h1>
<select id="database" name="database">
<option>Select Database</option>
<%
while(qe.rs.next())
{
%>
<option><%=qe.rs.getString(1)%></option>
<%
}
%>
</select>
&nbsp;&nbsp;<input type="button" value="Go"
name="dbconnectionbox" id="dbconnectionbox"
onclick="document.frm.action='DBMSNew.jsp';document.frm.submit();"/>
<br/><br/><hr/><br/>
<%
}

String database=request.getParameter("database");
qe = null;

if(database!=null)
{
db = new DBConnect(username,password,"");
qe = new QueryExecute(db,"Use "+database);
%>
<%=qe.status%>
<%=qe.error%>
<% }
}
}
%>
<script type="text/javascript">
function OnLoad()
{
document.getElementById('user').focus();
}
function Validate()
{
if(document.getElementById('user').value=="" ||
document.getElementById('pass').value=="")
{
alert('Field(s) Empty');
return false;
}
else
{
return true;
}
}
function Connect()
{
if(Validate()==true)
{
document.frm.action='DBMSNew.jsp';
document.frm.submit();
}
else
{
OnLoad();
}
}
</script>
</form></body></html>
OUTPUT:

Web Form:

DataBase:
DB Insertion in MySQL
import java.sql.*;
import javax.sql.*;

/*
* DBConnect.java
*
* Created on December 20, 2009, 3:04 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

/**
*
* @author vasu
*/

public class DBConnect


{
String user;
String pass;
String dbname;
String url;
Connection conn;
Statement stmt;
ResultSet rs=null;
ResultSetMetaData rsm=null;
boolean status=true;

boolean qestatus=true;
String querytype=null;
int count,row,col;

/** Creates a new instance of DBConnect */


public void CloseConn()
{
if(conn!=null)
{
try
{
conn.close();
System.out.println("Connection Terminated");
}
catch(Exception e1)
{
e1.toString();
}
}
}
void QueryExecute(String query)
{
try
{
stmt.executeQuery(query);
querytype="retrieve";
}
catch(Exception e)
{
try
{
count=stmt.executeUpdate(query);
System.out.println(count);
querytype="insert";
}
catch(Exception e1)
{
qestatus=false;
}
}
if(querytype.equals("retrieve")==true)
{
try
{
rs=stmt.getResultSet();
rsm=rs.getMetaData();
rs.last();
row=rs.getRow();
col=rsm.getColumnCount();
if(row<1 || col<1)
{
qestatus=false;
}
else
{
rs.first();
rs.previous();
}
}
catch(Exception e)
{
qestatus=false;
}
}
}
public DBConnect(String tuser,String tpass,String tdbname)
{
user=tuser;
pass=tpass;
dbname=tdbname;
url="jdbc:mysql://localhost/"+dbname;
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn=DriverManager.getConnection(url,user,pass);
stmt=conn.createStatement();
}
catch(Exception e)
{
status=false;
}
}

public static void main(String args[])


{
DBConnect db=new DBConnect("root","netwin","mobile");
db.QueryExecute("insert into dbinsert (name,cell,email) values
('ddf','123123','4@5.6')");
}
}

DB Deletion in MySQL
import java.sql.*;
import javax.sql.*;

/*
* DBConnect.java
*
* Created on December 20, 2009, 3:04 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

/**
*
* @author vasu
*/

public class DBConnect


{
String user;
String pass;
String dbname;
String url;
Connection conn;
Statement stmt;
ResultSet rs=null;
ResultSetMetaData rsm=null;
boolean status=true;

boolean qestatus=true;
String querytype=null;
int count,row,col;

/** Creates a new instance of DBConnect */


public void CloseConn()
{
if(conn!=null)
{
try
{
conn.close();
System.out.println("Connection Terminated");
}
catch(Exception e1)
{
e1.toString();
}
}
}
void QueryExecute(String query)
{
try
{
stmt.executeQuery(query);
querytype="retrieve";
}
catch(Exception e)
{
try
{
count=stmt.executeUpdate(query);
System.out.println(count);
querytype="insert";
}
catch(Exception e1)
{
qestatus=false;
}
}
if(querytype.equals("retrieve")==true)
{
try
{
rs=stmt.getResultSet();
rsm=rs.getMetaData();
rs.last();
row=rs.getRow();
col=rsm.getColumnCount();
if(row<1 || col<1)
{
qestatus=false;
}
else
{
rs.first();
rs.previous();
}
}
catch(Exception e)
{
qestatus=false;
}
}
}
public DBConnect(String tuser,String tpass,String tdbname)
{
user=tuser;
pass=tpass;
dbname=tdbname;
url="jdbc:mysql://localhost/"+dbname;
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn=DriverManager.getConnection(url,user,pass);
stmt=conn.createStatement();
}
catch(Exception e)
{
status=false;
}
}

public static void main(String args[])


{
DBConnect db=new DBConnect("root","netwin","mobile");
db.QueryExecute("delete from dbinsert where sno='3'");
}
}

OUTPUT:
DB Updation in MySQL
import java.sql.*;
import javax.sql.*;

/*
* DBConnect.java
*
* Created on December 20, 2009, 3:04 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

/**
*
* @author vasu
*/

public class DBConnect


{
String user;
String pass;
String dbname;
String url;
Connection conn;
Statement stmt;
ResultSet rs=null;
ResultSetMetaData rsm=null;
boolean status=true;

boolean qestatus=true;
String querytype=null;
int count,row,col;
/** Creates a new instance of DBConnect */
public void CloseConn()
{
if(conn!=null)
{
try
{
conn.close();
System.out.println("Connection Terminated");
}
catch(Exception e1)
{
e1.toString();
}
}
}
void QueryExecute(String query)
{
try
{
stmt.executeQuery(query);
querytype="retrieve";
}
catch(Exception e)
{
try
{
count=stmt.executeUpdate(query);
System.out.println(count);
querytype="insert";
}
catch(Exception e1)
{
qestatus=false;
}
}
if(querytype.equals("retrieve")==true)
{
try
{
rs=stmt.getResultSet();
rsm=rs.getMetaData();
rs.last();
row=rs.getRow();
col=rsm.getColumnCount();
if(row<1 || col<1)
{
qestatus=false;
}
else
{
rs.first();
rs.previous();
}
}
catch(Exception e)
{
qestatus=false;
}
}
}
public DBConnect(String tuser,String tpass,String tdbname)
{
user=tuser;
pass=tpass;
dbname=tdbname;
url="jdbc:mysql://localhost/"+dbname;
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn=DriverManager.getConnection(url,user,pass);
stmt=conn.createStatement();
}
catch(Exception e)
{
status=false;
}
}

public static void main(String args[])


{
DBConnect db=new DBConnect("root","netwin","mobile");
db.QueryExecute("update dbinsert set name='vvk' where sno='2'");
}
}
OUTPUT:

BEFORE:

AFTER:
XML File for Student

import javax.swing.*;
import java.io.*;
/*
* XML.java
*
* Created on December 20, 2009, 6:39 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

/**
*
* @author vasu
*/
public class XML
{

/** Creates a new instance of XML */


public XML()
{
String name=null,rollno=null,branch=null,year=null;
String str=null;
byte c[];
FileOutputStream fout=null;
try
{
fout=new FileOutputStream("C:\\XML.txt");
str=new String("<xml version='1.0'>\n<student>");
c=str.getBytes();
fout.write(c);
}
catch(Exception e)
{
e.printStackTrace();
}
//int c=0;
do
{
name=JOptionPane.showInputDialog("Enter Name:");
rollno=JOptionPane.showInputDialog("Enter Roll No:");
branch=JOptionPane.showInputDialog("Enter Branch:");
year=JOptionPane.showInputDialog("Enter Year:");

try
{
str=new String("\n\t<studentinfo>");
c=str.getBytes();
fout.write(c);

str=new String("\n\t\t<name>"+name+"<\\name>");
c=str.getBytes();
fout.write(c);

str=new String("\n\t\t<rollno>"+rollno+"<\\rollno>");
c=str.getBytes();
fout.write(c);

str=new String("\n\t\t<branch>"+branch+"<\\branch>");
c=str.getBytes();
fout.write(c);

str=new String("\n\t\t<year>"+year+"<\\year>");
c=str.getBytes();
fout.write(c);

str=new String("\n\t<\\studentinfo>");
c=str.getBytes();
fout.write(c);
}
catch(Exception e)
{
e.printStackTrace();
}
//System.out.println(c);
}while((JOptionPane.showConfirmDialog(null,"Do You Wish to Enter
More??"))==0);
//System.out.println(c);

try
{
str=new String("\n<\\student>");
c=str.getBytes();
fout.write(c);
fout.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String args[])
{
XML xml=new XML();
}
}

OUTPUT:

XML File Created Automatically:


<xml version='1.0'>
<student>
<studentinfo>
<name>llkasds<\name>
<rollno>dddd<\rollno>
<branch>aaaa<\branch>
<year>ssss<\year>
<\studentinfo>

<studentinfo>
<name>dddd<\name>
<rollno>eeee<\rollno>
<branch>ffff<\branch>
<year>kkkk<\year>
<\studentinfo>
<\student>

Servlet to Display Current Date and Time

/*
* Time.java
*
* Created on December 20, 2009, 9:05 PM
*/

/**
*
* @author vasu
* @version
*/
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.Date;

public class Time extends HttpServlet


{
public void doGet(HttpServletRequest req, HttpServletResponse rsp)throws
ServletException, IOException
{
rsp.setContentType("text/html");
PrintWriter out = rsp.getWriter();

Date now = new Date(); // The current date/time

out.println("<html>");
out.println("<head><title> Time Check </title></head>");
out.println("<body>");
out.println("<p>The time is: " + now + "</p>");
out.println("</body></html>");
}
}

OUTPUT:
Yahoo Sign Up Page
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"


"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Yahoo Sign Up Page</title>
</head>
<body>

<h1>Yahoo Sign Up Page</h1>


<br/><hr/><br/>
<table border="0">
<tr>
<td>Name:</td>
<td><input type="text" name="fname" value="First Name"
readonly="readonly" />&nbsp;&nbsp;<input type="text" name="lname"
value="Last Name" readonly="readonly" /></td>
</tr>
<tr>
<td>Sex:</td>
<td><select name="sex">
<option selected>Select Sex</option>
<option>Male</option>
<option>Female</option>
</select></td>
</tr>
<tr>
<td>DOB:</td>
<td><input type="text" name="dd" value="dd"
size="5"/>&nbsp;&nbsp;<input type="text" name="mm" value="mm"
size="5"/>&nbsp;&nbsp;<input type="text" name="yy" value="yy"
size="5"/></td>
</tr>
</table>
<br/><br/>
<table width="100%"><tr><td bgcolor="black"><font color="White">Sign Up
Name and Password</font></td></tr></table>
<hr/><br/>

<table border="0">
<tr>
<td>Requested Id:</td>
<td><input type="text" name="userid" value="" />&nbsp;&nbsp;<input
type="text" name="yahoo.com" value="@yahoo.com" readonly="readonly"
/></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="pass" value="" /></td>
</tr>
<tr>
<td>Retype Password:</td>
<td><input type="password" name="rpass" value="" /></td>
</tr>

</table>
<br/><br/>
<table width="100%"><tr><td bgcolor="black"><font color="White">Security
Questions</font></td></tr></table>
<hr/><br/>

<table border="0">

<tr>
<td>Question 1:</td>
<td><select name="q1">
<option>What is the first name of your favourite uncle</option>
<option>Where did you meet your spouse</option>
<option>What is your Oldest Cousins Name</option>
</select></td>
</tr>
<tr>
<td>Answer:</td>
<td><input type="text" name="a1" value="" /></td>
</tr>
<tr>
<td>Question 2:</td>
<td><select name="q2">
<option>Where did you spend your honeymoon</option>
<option>What town was your father born in</option>
<option>What was your favourite food as a child</option>
</select></td>
</tr>
<tr>
<td>Answer:</td>
<td><input type="text" name="a2" value="" /></td>
</tr>

</table>
<br/><br/><hr/>
<table width="100%"><tr><td bgcolor="black" align="center"><input
type="button" value="Submit" /></td></tr></table>
<hr/><br/>
</body>
</html>

OUTPUT: