WT LAB MANUAL-MIT

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

PROGRAM-1

Write an HTML document to demonstrate table properties.

1. Creation of Table:

<html>
<center>
<table border="5">
<caption align="bottom">
<b> Table Demo </b>
</caption>
<tr> <td>This is Left cell-row 1</td> <td>This is Right cell -row 1</td> </tr>
<tr> <td>This is Left cell-row 2</td> <td>This is Right cell-row 2</td></tr>
</table>
</center>
</html>

Output:

This is Left cell-row 1 This is Right cell -row 1


This is Left cell-row 2 This is Right cell-row 2

Table 1.
2. Table with background Color:
<html>
<center>
<table border="2">
<caption align="bottom">
<b> Table Demo with Background color</b>
</caption>
<th bgcolor=yellow>Name</th>
<th bgcolor=yellow>Marks</th>
<tr align=center> <td bgcolor=red>A</td> <td bgcolor=green>92</td></tr>
<tr align=center> <td bgcolor=green>B</td> <td bgcolor=red>90</td></tr>
</table>
</center>
<br>
<center>
<table border="5" background="D://3128.jpg">
<caption align="bottom">
<b> Table Demo with Background image</b>
</caption>
<th>Name</th>
<th>Marks</th>
<tr align=center> <td>C</td> <td>88</td></tr>
<tr align=center> <td>D</td> <td>77</td></tr>
</table>
</center>
</html>

Name Marks

A 92

B 90

1
Table 2
3. Table with merging row and Column:

<html>
<head>
<title> Time Table of CSE branch </title>
</head>
<body>
<center>
<table border="1" align="center">
<tr align="center"> <th rowspan=2> Day <th colspan=3> Lecture Timings </tr>
<tr>
<th>9.00 to 11.00 <th>11.00 to 1.00 <th>2.00 to 4.00
</tr>
<tr align=center>
<td> Monday
<td>Data Structures
<td>Theory of Computation
<td>Internet Programming
</tr>
<tr align=center>
<td>Tuesday
<td>Operating System
<td>Computer network
<td>Computer organisation
</tr>
<tr align=center>
<td>Wednesday
<td>Theory of Computation
<td>Computer network
<td>Data Structures
</tr>
<tr align=center>
<td>Thursday
<td>Internet Programming
<td>Computer organisation
<td>Data Structures
</tr>
<tr align=center>
<td>Friday
<td>Operating System
<td>Computer network
<td>Internet Programming
</tr>
<caption align=bottom><b><br> Time Table<b></caption>
</table>
</center>
</body>
</html>

Lecture Timings
Day
9.00 to 11.00 11.00 to 1.00 2.00 to 4.00
Monday Data Structures Theory of Computation Internet Programming
Tuesday Operating System Computer network Computer organisation
Wednesday Theory of Computation Computer network Data Structures
Thursday Internet Programming Computer organisation Data Structures
Friday Operating System Computer network Internet Programming

Table: 3

2
PROGRAM-2

Write an HTML document to demonstrate Form and its elements.

1. Text Box:

<html>
<head>
<title>My Page</title>
</head>
<body>
<form>
<input type="text" size="30" value=" ">
</form>
</body>
</html>

Enter Your Name

2. Text Area:

<html>
<head>
<title>My Page</title>
</head>
<body>
<form>
<div align="center">
<textarea cols="40" rows="5" name="myname">
</textarea>
<br><br>
</div>
</form>
</body>
</html>

3. Check Boxes:

<html>
<head>
<title>My Form with Check box</title>
</head>
<body>
<form name ="checkboxForm">
<div align="center"><br>
<input type="checkbox" name="option1" value="MCA" checked>MCA<br>
<input type="checkbox" name="option2" value="M.TECH">M.TECH<br>
<input type="checkbox" name="option3" value="B.TECH">B.TECH<br>
<br>

3
</div>
</form>
</body>
</html>

MCA
M.TECH
B.TECH

4. Radio Buttons

<html>
<head>
<title>My Form with radio buttons Page</title>
</head>
<body>
<form name="myform">
<div align="left"><br>
<input type="radio" name="group1" value="MCA">MCA<br>
<input type="radio" name="group1" value="M.TECH" checked> M.TECH<br>
<input type="radio" name="group1" value=" B.TECH"> B.TECH

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

MCA
M.TECH
B.TECH

5. Using Button:

<html>
<head>
<title>My Page</title>
</head>
<body>
<form>
<div align="center">
<br><br>
<input type="text" size="35" value="Enter your name ">
<br><input type="submit" value="Send">
<input type="reset" value="Reset"><br>
</div>
</form>
</body>
</html>

4
6. Using Menu List:

<html>
<head>
<title>My Page</title>
</head>
<body>
<form name>
<div align="center">
<select>
<option value="MCA">MCA</option>
<option value="M.TECH">M.TECH</option>
<option selected value="B.TECH">B.TECH </option>
<option value="BCA">BCA</option>
</select>
</div>
</form>
</body>
</html>

5
PROGRAM-3
Write java script program to demonstrate pop boxes.

1. Confirm Box, prompt box, alert box. ( on load the confirm box appears if click on Cancel button
then the prompt box will appear. On Click ok button alert box will appear.
<html>
<head>
<title>Introduction to pop up box</title>
</head>
<body>
<p>Experiment with the popup boxes by clicking the buttons(OK and Cancel) on them</p>

<script type="text/javascript">
if(confirm("do you agree?"))
alert("You have agreed");
else
input_text=prompt("Enter some string here..."," ");
/*the value entered in prompt box is returned
and stored in the variable text */
alert("Hi "+input_text);
</script>
</body>
</html>

Confirm Box

Prompt Box Alert Box

6
PROGRAM-4
Write java script program to demonstrate pattern matching using regular expression.
<html>
<head>
<title>Pattern Matching using Regular Expression </title>
<script type="text/javascript">
function TestString(str)
{
document.write("The given string is: ");
document.write("<em>"+str+"</em>"+"<br/>");
if(str.match(/computer/i))//case insensitive
alert("Match is found");
else
alert("Invalid Input");
}
</script>
</head>
<body>
<script type="text/javascript">
var input_str=prompt("Enter the word 'computer' in any case","");
TestString(input_str);
</script>
</body>
</html>

7
PROGRAM-5
Write an HTML document the move the position of an image by receiving the values of X and Y
coordinates.

<html>
<head>
<title>Moving the element</title>
<script type="text/javascript">
function my_fun(x_pos,y_pos)
{
var Dom_obj=document.getElementById("my_img").style;
Dom_obj.top=y_pos+"px";;
Dom_obj.left=x_pos+"px";
}
</script>
</head>
<body>
<form>
<label>X Co-ordinate:
<input type="text" value="10" id="x"/>
</label>
<label>Y Co-ordinate:
<input type="text" value="50" id="y"/>
</label>
<input type="button" value="Move" onclick="my_fun(x.value,y.value);"/>
</form>
<div id="my_img" style="position:absolute;top:50px;left:10px;">
<img src="fruit.jpg" />
</div>
</body>
</html>

8
PROGRAM-6

Write a document using DHTML for changing the foreground and background color.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Change Color Demo</title>
<script type="text/javascript">
function my_fun()
{
var F_color=document.getElementById("fore_color").value;
var B_color=document.getElementById("back_color").value;
document.body.style.backgroundColor=B_color;
document.body.style.color=F_color;
}
</script>
</head>
<body>
<h2>Change Color!!!</h2>
<form>
<label>Enter foreground color
<input type="text" value="" id="fore_color"/>
</label>
<br/><br/>
<label>Enter Background color
<input type="text" value="" id="back_color"/>
</label>
<br/><br/>
<input type="button" value="click to change the color" onclick="my_fun();"/>
</form>
</body>
</html>

9
PROGRAM-7
Write a DHTML document to control the visibility of a particular element.
<html>
<head>
<title>Visibility Of Element</title>
<script type="text/javascript">
function my_fun()
{
var Dom_obj=document.getElementById("my_img").style;
if(Dom_obj.visibility=="visible")
Dom_obj.visibility="hidden";
else
Dom_obj.visibility="visible";
}
</script>
</head>
<body>
<form>
<input type="button" value="Show/Hide" onclick="my_fun();"/>
</form>
<div id="my_img" style="position:absolute;top:10px;left:100px;">
<img src="bird.jpg" />
</div>
</body>
</html>

10
PROGRAM-8
Write programs using Java script for Web Page to display browsers information.
Navigator Cookie Enabled

The property cookieEnabled returns true if cookies are enabled, otherwise false:

<!DOCTYPE html>
<html>
<body>

<p>Are cookies enabled in your browser?</p>


<button onclick="myFunction()">Try it</button>
<p id="demo"></p>

<script>
function myFunction() {
document.getElementById("demo").innerHTML =
"Cookies enabled is " + navigator.cookieEnabled;
}
</script>
</body>
</html>

The Browser Names

The properties appName and appCodeName return the name of the browser:

<!DOCTYPE html>
<html>
<body>
<p>What is the name(s) of your browser?</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
document.getElementById("demo").innerHTML =
"Name is " + navigator.appName +
"<br>Code name is " + navigator.appCodeName;
}
</script>
</body>
</html>

The Browser Engine

The property product returns the engine name of the browser:


<!DOCTYPE html>
<html>
<body>

<p>Display browser engine.</p>


<button onclick="myFunction()">Try it</button>
<p id="demo"></p>

<script>
function myFunction() {
document.getElementById("demo").innerHTML =
"Browser engine is " + navigator.product;
}
</script>
</body>
</html>
11
The Browser Engine

The property product returns the engine name of the browser:


<!DOCTYPE html>
<html>
<body>

<p>Display browser engine.</p>


<button onclick="myFunction()">Try it</button>
<p id="demo"></p>

<script>
function myFunction() {
document.getElementById("demo").innerHTML =
"Browser engine is " + navigator.product;
}
</script>
</body>
</html>

The Browser Version I

<!DOCTYPE html>
<html>
<body>

<p>Display version information about the browser.</p>


<button onclick="myFunction()">Try it</button>
<p id="demo"></p>

<script>
function myFunction() {
document.getElementById("demo").innerHTML =
navigator.appVersion;
}
</script>
</body>
</html>

The Browser Version II

The property userAgent also returns version information about the browser:

<!DOCTYPE html>
<html>
<body>
<p>Display the user-agent header sent by the browser to the server.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
document.getElementById("demo").innerHTML =
navigator.userAgent;
}
</script>
</body>
</html>

12
Note 

The information from the navigator object can often be misleading, and should not be used to detect browser versions because:

 Different browsers can use the same name


 The navigator data can be changed by the browser owner
 Some browsers misidentify themselves to bypass site tests
 Browsers cannot report new operating systems, released later than the browser

Is Java Enabled?

<!DOCTYPE html>
<html>
<body>

<p>Is Java enabled?</p>


<button onclick="myFunction()">Try it</button>
<p id="demo"></p>

<script>
function myFunction() {
document.getElementById("demo").innerHTML =
"Java enabled is " + navigator.javaEnabled();
}
</script>
</body>
</html>

The Browser Platform

The property platform returns the browser platform (operating system):

<!DOCTYPE html>
<html>
<body>

<p>Display browser platform.</p>


<button onclick="myFunction()">Try it</button>
<p id="demo"></p>

<script>
function myFunction() {
document.getElementById("demo").innerHTML =
navigator.platform;
}
</script>
</body>
</html>

13
PROGRAM-9
Write a Java applet to display the Application Program screen i.e. calculator and other.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class Calc extends Applet implements ActionListener


{

String cmd[]={"+","-","*","/","=","C"};
int pv=0;
String op="";
Button b[]=new Button[16];
TextField t1=new TextField(10);

public void init()

setLayout(new BorderLayout());
add(t1,"North");
t1.setText("0");
Panel p=new Panel();
p.setLayout(new GridLayout(4,4));
for(int i=0;i<16;i++)
{

if(i<10)
b[i]=new Button(String.valueOf(i));

else
b[i]=new Button(cmd[i%10]);

b[i].setFont(new Font("Arial",Font.BOLD,25));
p.add(b[i]);
add(p,"Center");
b[i].addActionListener(this);

}
}

public void actionPerformed(ActionEvent ae)


{

int res=0;
String cap=ae.getActionCommand();
int cv=Integer.parseInt(t1.getText());

if(cap.equals("C"))
{

t1.setText("0");
pv=0;
cv=0;
res=0;
op="";

14
}

else if(cap.equals("="))
{
res=0;

if(op=="+")
res=pv+cv;

else if(op=="-")
res=pv-cv;

else if(op=="*")
res=pv*cv;

else if(op=="/")
res=pv/cv;

t1.setText(String.valueOf(res));
}

else if(cap.equals("+")||cap.equals("-")||
cap.equals("*")||cap.equals("/"))
{

pv=cv;
op=cap;
t1.setText("0");

else
{

int v=cv*10+Integer.parseInt(cap);
t1.setText(String.valueOf(v));

}
}
}

Output:

15
PROGRAM-10
Write a program in XML for creation of DTD, which specifies set of rules. Create a style sheet in
CSS/ XSL & display the document in internet explorer.

AIM: Write an XML file which will display the Book information which includes the
following:
1) Title of the book
2) Author Name
3) ISBN number
4) Publisher name
5) Edition
6) Price
Write a Document Type Definition (DTD) to validate the above XML file.
Display the XML file as follows.
The contents should be displayed in a table. The header of the table should be in color GREY.
And the Author names column should be displayed in one color and should be capitalized and in
bold. Use your own colors for remaining columns. Use XML schemas XSL and CSS for the
above purpose.

1. Books.DTD:
<!ELEMENT details (title, author, ISBN_Number, publisher, edition, price) >
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT ISBN_Number (#PCDATA)>
<!ELEMENT publisher (#PCDATA)>
<!ELEMENT edition (#PCDATA)>
<!ELEMENT price (#PCDATA)>

2. Th.CSS
.thb
{
background-color:gray;
}
.bg
{
background-color:red;
}

3. Books.XML:
<?xml version="1.0"?>
<!DOCTYPE book SYSTEM "books.dtd">
<book>
<details>
<title> C</title>
<author> BalaGuru Swami</author>
<ISBN_Number>2536</ISBN_Number>
<publisher>pearson</publisher>
<edition>2</edition>
<price>255/-</price>
</details>
<details>
<title> C++</title>
<author> BalaGuru Swami</author>
<ISBN_Number>5236</ISBN_Number>
<publisher>pearson</publisher>
<edition>2</edition>
<price>315/-</price>
</details>
<details>
<title> E-Commerce</title>
<author> Kalakata</author>
16
<ISBN_Number>8562</ISBN_Number>
<publisher>pearson</publisher>
<edition>5</edition>
<price>300/-</price>
</details>
<details>
<title> CO</title>
<author> Marris </author>
<ISBN_Number>4578</ISBN_Number>
<publisher>Dream Tech</publisher>
<edition>5</edition>
<price>270/-</price>
</details>
<details>
<title> Web Technologies</title>
<author> Kumar </author>
<ISBN_Number>5423</ISBN_Number>
<publisher>Willay</publisher>
<edition>6</edition>
<price>500/-</price>
</details>
<details>
<title> Web Programming</title>
<author> Kumar </author>
<ISBN_Number>1258</ISBN_Number>
<publisher>Willay</publisher>
<edition>6</edition>
<price>500/-</price>
</details>
</book>

4. Books.HTML:
<html>
<head>
<link rel="stylesheet" type="text/css" href="th.css">
</head>
<body>
<script type="text/javascript">
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","books.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
document.write("<table border='1'>");
var x=xmlDoc.getElementsByTagName("details")
document.write("<tr><th class='thb'>");
document.write("TITLE</th><th class='thb'>AUTHOR</th><th
class='thb'>ISBN_Number</th><th class='thb'>PUBLISHER</th><th
class='thb'>EDITION</th><th class='thb'>PRICE</th></tr>");
for (i=0;i<x.length;i++)
{
document.write("<tr><td>");
document.write(x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue);
document.write("</td><th class='bg'>");
document.write(x[i].getElementsByTagName("author")[0].childNodes[0].nodeValue.toU
pperCase());
document.write("</th><td>");
document.write(x[i].getElementsByTagName("ISBN_Number")[0].childNodes[0].nodeV
17
alue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("publisher")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("edition")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("price")[0].childNodes[0].nodeValue);
document.write("</td></tr>");
}

document.write("</table>");
</script>
</body>
</html>

Output:

18
PROGRAM-11
Program to illustrate JDBC connectivity. Program for maintaining database by sending queries.
Design and implement a simple servlet book query with the help of JDBC & SQL. Create MS
Access Database, Create on ODBC link, Compile & execute JAVA JDVC Socket.

Main.html:
<html>
<body>
<br /><br /><br /><br /><br />
<h1 align="center"><U>ONLINE BOOK STORAGE</U></h1><br/><br /><br />
<h2 align="center"><pre>
<b>Welcome to online book storage.
Press LOGIN if you are having id
otherwise press REGISTRATION
</b></pre></h2>
<br /><br /><pre>
<div align="center"><a href="login.html">LOGIN</a> <a href="reg.html">
REGISTRATION</a></div></pre>
</body>
</html>

login.html:
<html>
<body><br /><br /><br />
<form name="myform" method="post" action="login">
<div align="center"><pre>
LOGIN ID :<input type="text" name="id" /><br />
PASSWORD :<input type="password" name="pwd" /></pre><br /><br />
</div>
<br /><br />
<div align="center">
<input type="submit" value="ok"/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="clear" />
</div>
</form>
</body>
</html>

Profile.html
<html>
<body><br /><br /><br />
<form name="myform" method="post" action="profile">
<div align="center"><pre>
LOGIN ID :<input type="text" name="id" /><br />
</pre><br /><br />
</div>
<br /><br />
<div align="center">
<input type="submit" value="ok" onclick="validate()" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="clear" />
</div>
</form>
</body>
</html>

19
Userinfo.html
<html>
<head>
<title>User Info Entry Form</title>
</head>
<body bgcolor="white">
<form action="userinfo1.jsp" method="post">
<table>
<tr>
<td>Name:</td>
<td><input type="text" name="userName" >
</td>
</tr>
<tr>
<td>Sex:</td>
<td><input type="text" name="sex" >
</td>
<td>(Male or female)</td>
</tr>
<tr>
<td colspan=2><input type="submit"></td>
</tr>
</table>
</form>
</body>
</html>

Reg.html
<html>
<body><br /><br />
<form name="myform" method="post" action="reg">
<table align="center" >
<tr>
<td>NAME</td>
<td>:<input type="text" name="name" /></td>
</tr>
<tr>
<td>ADDRESS</td>
<td>:<input type="text" name="addr" /></td>
</tr>
<tr>
<td>CONTACT NUMBER</td>
<td>:<input type="text" name="phno" /></td>
</tr>
<tr>
<td>LOGINID</td>
<td>:<input type="text" name="id" /></td>
</tr>
<tr>
<td>PASSWORD</td>
<td>:<input type="password" name="pwd" /></td>
</tr>
</table>
<br /><br />
<div align="center">
<input type="submit" value="ok" onclick="validate()" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="clear" />
</div>
</form>
</body>

20
</html>

login.java
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class login extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse resp)
throws ServletException,IOException
{
PrintWriter pw=resp.getWriter();
pw.println("<html><body>");
String id=req.getParameter("id");
String pwd=req.getParameter("pwd");
String s1="",s2="";
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1522:XE","system",
"tiger");
Statement stmt=con.createStatement();
String sqlstmt="select * from login";
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next())
{
s1=rs.getString(4);
s2=rs.getString(5);
}
if(id.equals(s1)&&pwd.equals(s2))
{
flag=1;
}
if(flag==0)
{
pw.println("<br><br>SORRY INVALID ID TRY AGAIN ID<br><br>");
pw.println("<a href=\"login.html\">press LOGIN to RETRY</a>");
}
else
{
pw.println("<br><br>WELCOME TO "+id.toUpperCase()+"<br><br>");
pw.println("<h3><ul>");
pw.println("<li><a href=\"profile.html\"><fontcolor=\"black\">
USER PROFILE</font></a></li><br><br>");
pw.println("<li><a href=\"catalog.html\"><fontcolor=\"black\">BOOKS
CATALOG</font></a></li><br><br>");
pw.println("<li><a href=\"order.html\"> <fontcolor=\"black\">ORDER
CONFIRMATION</font></a></li></ul><br><br>");
}
pw.println("</body></html>");
}
catch(Exception e)
{
resp.sendError(500,e.toString());
}
}
}
21
reg.java:
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class reg extends HttpServlet
{
public void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException,IOException
{
PrintWriter pw=resp.getWriter();
resp.setContentType("text/html");
pw.println("<html><body>");
String name=req.getParameter("name");
String addr=req.getParameter("addr");
String phno=req.getParameter("phno");
String id1=req.getParameter("id");
String pwd1=req.getParameter("pwd");
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection
("jdbc:oracle:thin:@localhost:1522 :XE","system","tiger");
Statement stmt=con.createStatement();
String sqlstmt="select * from login";
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next())
{
if(id1.equals(rs.getString(4))&&pwd1.equals(rs.getString(5)))
{
flag=1;
}
}
if(flag==1)
{
pw.println("<br><br>SORRY INVALID ID ALREADY EXITS
TRY AGAIN WITH NEW ID<br><br>");
pw.println("<a href=\"reg.html\">press REGISTER to RETRY</a>");
}
else
{
Statement stmt1=con.createStatement();
stmt1.executeUpdate("insert into login values
('"+name+"','"+addr+"','"+phno+"','"+id1+"','"+pwd1+"')");
pw.println("<br><br>YOUR DETAILS ARE ENTERED<br><br>");
pw.println("<a href=\"login.html\">press LOGIN to login</a>");
}
pw.println("</body></html>");
}
catch(Exception e)
{
resp.sendError(500,e.toString());
}
}
}

22
profile.java:
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class profile extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse resp)
throws ServletException,IOException
{
PrintWriter pw=resp.getWriter();
pw.println("<html><body>");
String id=req.getParameter("id");
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1522:XE","system","tiger");
Statement stmt=con.createStatement();
String sqlstmt="select * from login where id='"+id+"'";
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
pw.println("<br><br><br>");
while(rs.next())
{
pw.println("<div align=\"center\">");
pw.println("NAME :"+rs.getString(1)+"<br>");
pw.println("ADDRESS :"+rs.getString(2)+"<br>");
pw.println("PHONE NO :"+rs.getString(3)+"<br>");
pw.println("</div>");
flag=1;
}
if(flag==0)
{
pw.println("<br><br>SORRY INVALID ID TRY AGAIN ID<br><br>");
pw.println("<a href=\"profile.html\">press HERE to RETRY</a>");
}
pw.println("</body></html>");

Order.java:
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class order extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse resp)
throws ServletException,IOException
{
int count;
PrintWriter pw=resp.getWriter();
pw.println("<html><body>");
23
String id=req.getParameter("id");
String pwd=req.getParameter("pwd");
String title=req.getParameter("title");
String count1=req.getParameter("no");
String date=req.getParameter("date");
String cno=req.getParameter("cno");
try
{
count=Integer.parseInt(count1);
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1522:XE","system","tiger");
Statement stmt=con.createStatement();
String sqlstmt="select * from login";
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0,amount,x;
while(rs.next())
{
if(id.equals(rs.getString(4))&&pwd.equals(rs.getString(5)))
{
flag=1;
}
}
if(flag==0)
{
pw.println("<br><br>SORRY INVALID ID TRY AGAIN ID<br><br>");
pw.println("<a href= \" order.html \" >press HERE to RETRY</a>");
}
else
{
Statement stmt2=con.createStatement();
String s="select cost from book where title='"+title+"'";
ResultSet rs1=stmt2.executeQuery(s);
int flag1=0;
while(rs1.next())
{
flag1=1;
x=Integer.parseInt(rs1.getString(1));
amount=count*x;
pw.println("<br><br>AMOUNT:"+amount+"<br><br><br><br>");
Statement stmt1=con.createStatement();
stmt1.executeUpdate("insert into details values('"+id+"','"+title+"','"+amount+"','"+cno+"')");
pw.println("<br>YOUR ORDER has taken<br>");
}
if(flag1==0)
{
pw.println("<br><br><br>SORRY INVALID ID TRY AGAIN ID<br><br>");
pw.println("<a href=\"order.html\">press HERE to RETRY</a>");
}
}
pw.println("</body></html>");
con.close();
}
catch(Exception e)
{
resp.sendError(500,e.toString());
}
}
}

24

You might also like