0% found this document useful (0 votes)
91 views

WT Lab PRO

The document describes designing static web pages for an online book store. It includes HTML code for framesets and pages for navigation, login, registration, user profile, books catalog, payment and order confirmation.

Uploaded by

Raghu Suveer
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views

WT Lab PRO

The document describes designing static web pages for an online book store. It includes HTML code for framesets and pages for navigation, login, registration, user profile, books catalog, payment and order confirmation.

Uploaded by

Raghu Suveer
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 85

Pgm no: 1 Date: Aim: Design the static web pages require for an online book store website

Program: Frame.html: <html> <frameSet rows="30%,*"> <frame name=f1 src="h.html"> </frame> <frameSet cols="30%,*"> <frame name=f2 src="h3.html"> </frame> <frame name=f3 src=" h1.html"> </frame> </frameSet> </frameSet> </html>

pg.

h.html: <html> <marquee>welcome to online book shopping </marquee> </html>

h2.html: <html> <h1>successfully login</h1> </html>

h3.html: <html> <ul type=disc> <li> <a href=home.html target=f3>Home page</a> </li> <li> <a href=reg.html target=f3 > registration</a>
pg.
2

</li> <li> <a href=user.html target=f3>user profile</a> </li> <li> <a href=login.html target=f3>login</a> </li> <li> <a href=book.html target=f3>books catalog</a> </li> <li> <a href=reg.html target=f3>payment by credit</a> </li> <li> <a href=conf.html target=f3>order confirmation</a> </li> </ul> </html>

home.html:
pg.
3

<html> <body bgcolor="blue"> <h2 style="margin-top:55px"> welcome to online book shop this website provide all books info </h2> </body> </html>

reg.html: <html> <form action=h1.html> enter name<input type=text><br> user id<input type=text><br> password<input type=password><br> mobile no<input type=text><br> city<input type=text><br> <input type=submit value=submit> </form> </html>
pg.
4

user.html: <html> <table border=2 bgcolor="meganta"> <caption>user profile</caption> <tr> <th>name</th> <th>user id</th> <th>mobile no</th> <th>city</th> </tr> <tr> <td>xyz</td> <td>x-yz</td> <td>9642550244</td> <td>hyd</td> </tr> <tr> <td>abc</td> <td>abcd</td>
pg.
5

<td>9701234567</td> <td>bang</td> </tr></table></html>

login.html: <html> <form action =h2.html> user id<input type=text> pass word<input type=password> <input type=submit value=login> </form> </html>

book.html: <html> <table border=2 bgcolor=red> <caption>Book details</caption> <tr> <th>book id</th>
pg.
6

<th>book name</th> <th>price</th> </tr> <tr> <td>1520</td> <td>web technologies</td> <td>rs.200</td> </tr> <tr> <td>1521</td> <td>java</td> <td>Rs.300</td> </tr> </html>

payment.html: <html> <form action=reg.html> userid<input type=text><br> mobileno<input type=text><br>


pg.
7

bookid<input type=text><br> creditno<input type=text><br> <input type="submit" value=order> </form> </html> conf.html: <html> <p style="margin left=55px"> thanks for visiting the website.we will deliver book in 10 days </p> </html>

h1.html: <html> <h1>Welcome </h1> </html>

pg.

Output:

Welcome to online book shopping

Home page registration user profile login books catalog payment by credit order confirmation

enter name user id password mobile no city

pg.

Pgm no: 2 Date: Aim To design a web page using different font type and color and size first.html <html> <head> <link rel="StyleSheet" type="text/css" href="csss.css"/> </head> <body> <h1>This Header is Red</h1>
pg.
10

<h2>This Header is Blue</h2> <p>This Header is Normal</p> </body> </html>

Css.css h1 {color:red; font-size:22px; font-family:arial; text:decoration} h2 {color:blue; font-size:16px} p {font-family: font-size:px}

Output:

pg.

11

pg.

12

Aim To design a webpage by setting background image Second.html <html> <head> <style type="text/css"> body { background-image:url("C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Winter.jpeg "); background-repeat:no-repeat; } </style> </head> <body> <center> <h1>Steve Jobs</h1> </body> </center> </html>

pg.

13

Output:

pg.

14

Aim: To display a web page by setting repeat background image Third.html <html> <head> <style type="text/css"> body { background-image:url("C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Winter.jpeg"); background-repeat:repeat; } </style> </head> <body> <center> <h1>Steve Jobs</h1> </body>
pg.
15

</center> </html>

Output:

pg.

16

Aim: Ti design a web page using different style for links Fourth.html <html> <head> <link rel="StyleSheet" type="text/css" href="text4.css"/> </head> <body> <h1>This style sheet is for links</h1> <p>you can experiment with following link</p> <p ><a href="first.html">this is a link</a></p> </body> </html>

pg.

17

Output:

pg.

18

AIM: To design web page usin layers. Fifth.html <html> <head> <title> Layer DEMO </title> <body> <div style="position:relative; font-size:50px; left:50; top:10; background-color:red;
pg.
19

i-index:1">layer1</div> <div style="position:relative; font-size:50px; left:150; top:3; background-color:green; i-index:2">layer2</div> <div style="position:relative; font-size:50px; left:200; top:5; background-color:blue; i-index:3">layer3</div> </body> </html>

pg.

20

Output:

pg.

21

pg.

22

Aim: To display a page using different styles for links. Sixth.html <html> <head> <title>Cursor Demo</title> <style type="text/css"> .link1{cursor:default} .link2{cursor:crosshair} .link3{cursor:hand} .link4{cursor:move} .link5{cursor:text} .link6{cursor:wait} </style></head> <body> <a href="text.html" class="link1">Default Cursor</a><br> <a href="text.html" class="link2">crosshair</a><br> <a href="text.html" class="link3">hand</a><br> <a href="text.html" class="link4">move</a><br> <a href="text.html" class="link5">text</a><br> <a href="text.html" class="link6">wait</a><br></b></body>
pg.
23

</html>

Output:

pg.

24

Pgm no:3 Date: Aim: write a program for validation of payment by credit Program: Pay.html: <html> <script src="val.js"> </script> <body> <form name=f1 > <table> <tr><td>Enter name</td><td><input type=text name=n1></td></tr><br> <tr><td>Pass word</td><td><input type=password name=pwd></td></tr><br> <tr><td>Book id</td><td><input type=text name=bid></td></tr><br> <tr><td>Price</td><td><input type=text name=pri></td></tr><br>

pg.

25

<tr><td>Creditcard no</td><td><input type=password name=cno></td></tr><br> <tr><td><input type=button value=Buynow onclick="return val()"> <tr><td><input type=reset value=clear></td></tr> </table> </form> </body> </html>

Val.js: function val() { for(var i=0;i<=5;i++) { if(document.forms[0].elements[i].value=="") { alert("please enter all fields") document.forms[0].elements[i].focus(); return(false); }
pg.
26

} var t=document.forms[0].elements; var nre=new RegExp("[a-z][a-z]","g"); var pre=new RegExp("^[0-9][0-9][0-9]","g"); var bre=new RegExp("^[a-z][0-9]"); var n=t.n1.value; var pw=t.pwd.value; var bid=t.bid.value; var pr=t.pri.value; var cr=t.cno.value; if(n.match(nre)) { if(pw.length>6) { if(bid.match(bre)) { if(pr.match(pre)) { if(cr.length>6) {
pg.
27

return(true); } else { alert("enter correct card no"); } }//endofpr else { alert("enter correct price "); } }//end of bid else { alert("enter correct bookid"); } }//end of pw else
pg.
28

{ alert("enter correct password"); } } else {alert("enter correct name"); }} Output: Enter name Pass word Book id Price Creditcard no

pg.

29

Pgm no:4 Date: Aim: write html program for array based object Program: Array.html <html> <script> var a=[1,3,5,7]; for(var i=0;i<a.length;i++)
pg.
30

document.write("array ele"+a[i]+"<br>"); a.shift(); document.writeln("by shift ele are"+a.join(",")); a.push('a','b') ; document.writeln("after push"+a.join(",")+"<br>"); a.pop(); document.writeln("pop an element"+a.join(",")+"<br>"); a.unshift(2,4); document.writeln("after unshift"+a.join(",")+"<br>"); a.reverse(); document.writeln("reversed elements are "+a.join(",")); var b=a.slice(3,5); document.writeln(" elements in b are "+b.join(",")); var b=a.slice(3,0,"string","string1"); document.writeln(" elements in a are " +a.join(",")); var c=['a','b','c','d']; var d=a.concat(c); document.writeln(" array d " +d.join(",")); </script> </html>
pg.
31

Out put: array ele1 array ele3 array ele5 array ele7 by shift ele are3,5,7 after push3,5,7,a,b pop an element3,5,7,a after unshift2,4,3,5,7,a
pg.

32

reversed elements are a,7,5,3,4,2 elements in b are 3,4 elements in a are a,7,5,3,4,2 array d a,7,5,3,4,2,a,b,c,d

Pgm no:5 Date: Aim: write html program for text only menus Program: Text.html:
pg.
33

<html> <script src=s.js></script> <div id="m"style="Visibility:Visible"> <a href=# onmouseover="change('0')" onmouseout="unhighlight('0')">one</a> <a href=# onmouseover="change('1')" onmouseout="unhighlight('1')">two</a> <a href=# onmouseover="change('2')" onmouseout="unhighlight('2')">three</a> </div> <div id="m0"style="Visibility:hidden"> <a href=#>1</a> <a href=#>2</a> <a href=#>3</a></div> <div id="m1"style="Visibility:hidden"> <a href=#>4</a> <a href=#>5</a> <a href=#>6</a></div> <div id="m2"style="Visibility:hidden"> <a href=#>7</a> <a href=#>8</a>
pg.
34

<a href=#>9</a> </div> </html>

Val.js: function change(n) { document.all("m").style.visibility="hidden"; document.all("m"+n).style.visibility="visible"; } function unhighlight(n) { document.all("m").style.visibility="visible"; document.all("m"+n).style.visibility="hidden"; }

Output:

One two three

pg.

35

1 2 3

Pgm no:6 Date: Aim: write a java script for simple calculator Program:
pg.
36

Cal.html: <html> <head> <script language='JavaScript'> function add(){ var num1=parseInt(frm.first.value); var num2=parseInt(frm.second.value); var res=num1+num2; frm.result.value=res; } function sub(){ var num1=parseInt(frm.first.value); var num2=parseInt(frm.second.value); var res=num1-num2; frm.result.value=res; }

function mul() { var num1=parseInt(frm.first.value);


pg.
37

var num2=parseInt(frm.second.value); var res=num1*num2; frm.result.value=res; } </script> <style> .label {font-family:verdana;color:blue} .button {fontmamily:verdana;color:blue;border:0;background:pink;width:80 } </style> </head> <body bgcolor='lightgreen'> <center> <font color='blue' size='+3'> avr & svr College of Engineering & Technology<br> Calculator<br> </font> <table cellpadding='5' cellspacing='0'border='1'> <form name='frm'>
pg.
38

<tr><td class='label'>First Number</td><td><input type='text' name='first'></td></tr> <tr><td class='label'>Second Number</td><td> <input type='text' name='second'></td></tr> <tr><td class='label'>Result</td><td> <input type='text' name='result'></td></tr> <tr><td colspan=2 align='center'> <input type='button' value='Add' onClick='add()' class='button'> <input type='button' value='Sub' onClick='sub()' class='button'> <input type='button' value='Mul' onClick='mul()' class='button'> </td></tr> </form> </table> </center> </body></html>

pg.

39

Output: avr & svr College of Engineering & Technology Calculator First Number Second Number Result

pg.

40

Pgm no:7 Date: Aim :write a java script for validate username and password Program: Jspuser.html: <html> <head> <script language="javascript"> <!-function validate() { var uname=signin.mail.value; var upass=signin.ps.value; name_re=new RegExp("^[a-zA-Z][0-9a-zA-Z]+@(yahoo|rediff| hotmail).(com|edu|org)$","g"); pass_re=new RegExp("^[A-Za-z0-9][A-Za-z0-9]+$","g"); if((uname.match(name_re)) && (upass.match(pass_re)))
pg.
41

alert("username and password are proper"); else alert("username and password are not in proper format"); } </script> </head> <body text="purple" bgcolor='lightgreen'><center> <h1 align='center'>avr & svr College of Engineering & Technology</h1> <font color="blue" size="+2">Registration and user Login</font> <form name=signin> <table> <tr> <td style="font-family:Courier New;color:red;font-size:15pt;"> <u>Sign-in</u> &nbsp&nbsp&nbsp&nbsp&nbsp What is your email-Address?</td> </tr> <tr> <td>

pg.

42

My email Address is:<input type=text name=mail size=20 maxlength=30></td></tr> <tr><td>Do you have a password?<br> <input type=radio name=pass value="no">No, I am a new customer.</td> </tr> <tr><td><input type=radio name=pass value="yes">Yes, I have a password: <input type="password" name="ps" size="20"></td></tr> <tr><td align=center> <input type="button" name="sign" value="SignIn" style="color:blue" onClick=validate()></td></tr> </table> </form> </center> </body> </html>

pg.

43

Output: avr & svr College of Engineering & Technology Registration and user Login Sign-in What is your email-Address? My email Address is: Do you have a password? No, I am a new customer. Yes, I have a password:

pg.

44

Pgm no:8 Date: Aim: write a program using xml in html page Program: Emp.html: <html> <body> <xml id="emp" src="emp.xml"> </xml> <h2 align="center"> Using XML Island </h2> <form>
pg.
45

<table datasrc="#emp" align="center" border=1 datapagesize="2" id="t1"> <thead> <tr> <th>EmpNO</th> <th>Ename</th> <th>Salary</th> </tr> </thead> <tbody> <tr> <td><span datafld="empno"></td> <td><span datafld="ename"></td> <td><span datafld="sal"></td> </tr> </tbody> </table> <center> <input type=button value="Next" onClick="t1.nextPage()">

pg.

46

<input type=button value="Previous" onClick="t1.previousPage()"> </center> </form> </body> </html>

Emp.xml: <?xml version="1.0" ?> <emps> <emp> <empno>101</empno> <ename>kiran</ename> <sal>5000</sal> </emp> <emp> <empno>102</empno> <ename>raju</ename> <sal>6000</sal> </emp>
pg.
47

<emp> <empno>103</empno> <ename>kumar</ename> <sal>5600</sal> </emp> <emp> <empno>104</empno> <ename>sudha</ename> <sal>4500</sal> </emp> </emps>

Output: Using XML Island EmpNO Ename Salary 101 102 kiran raju 5000 6000

pg.

48

Pgm no:9 Date: Aim: validation using DTD Dtd.dtd <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?> <!DOCTYPE employees [<!ELEMENT employees (employee+)> <!ELEMENT employee (name+,record+)>
pg.
49

<!ELEMENT name (#PCDATA)> <!ELEMENT rercord (id?,hire-date?,department?,title?,sale+)> <!ELEMENT id (#PCDATA)> <!ELEMENT hire-date (#PCDATA)> <!ELEMENT department (#PCDATA)> <!ELEMENT title (#PCDATA)> <!ELEMENT sale (#PCDATA)> <!ELEMENT date (#PCDATA)> <!ELEMENT amount (#PCDATA)> <!ATTLIST amount currency (Rs|Dollar) #REQUIRED>]> <employees> <employee> <name>maha</name> <record> <id>543</id> <hire-date>06-06-1991</hire-date> <department>coding</department> <title>DEVELOPER</title> <sale><date>08-06-1991</date> <amount currency="Rs">32000.00</amount>
pg.
50

</sale> <sale><date>09-06-1991</date> <amount currency="Rs">43000.00</amount> </sale> <sale><date>10-06-1991</date> <amount currency="Rs">44000.00</amount> </sale> </record> </employee> <employee> <name>sahar</name> <record> <id>345</id> <hire-date>08-12-1991</hire-date> <department>coding</department> <title>DEVELOPER</title> <sale><date>08-12-1991</date> <amount currency="Rs">28000.00</amount> </sale> </record>
pg.
51

</employee> </employees>

Output:

pg.

52

pg.

53

Pgm no:10 Date: Aim: Program for finding given number is add or even Program: Servlet.html: <html> <head> <script> function fun() { if(form1.text1.value%2==0) alert("EVEN NUMBER"); else alert("ODD NUMBER"); } </script> </head> <body>

pg.

54

<center><h1> EVEN OR ODD NUM TESTING</h1></center> <form name="form1"> ENTER SOME NUMBER:<input type="text" name="text1"> <input type="button" value="Submit" onClick="fun()"> </frame> </body> </html>

pg.

55

OUTPUT:

pg.

56

Pgm no:11 Date: Aim: To design a string to display Armsrong umber in between 1 and 1000 Armstrong.html <html> <body> <table border="1" align="center"> <th>AMSTRONG NUMBER</th> <script> var num,i,sum; var n=0; i=1; do
pg.
57

{ num=i; sum=0; while(num>0) { n=num%10; n=parseInt(n); num=num/10; num=parseInt(num); sum=sum+(n*n*n); } if(sum==i) document.write("<tr><td align='center'>"+i+"</td></tr>"); i++; }while(i<1000); </script> </table> </html>

pg.

58

OUTPUT:

pg.

59

Pgm no:12 Date: Aim: To design script that display as per following. Squareandcube.html <html> <head><title>sqr and cube</title>></head> <body> <table border="1" align="center"> <th>Number</th> <th>Square</th> <th>cube</th>
pg.
60

<script> for(i=0;i<=10;i++) document.write("<tr><td>"+i+"</td><td>"+(i*i)+"</td><td>"+ (i*i*i)+"</td></tr>"); </script> </body> </html>

OUTPUT:

pg.

61

Pgm no:13
pg.
62

Date: Aim: To design web page for crediting dynamic feature. Dhtml.html <html> <head> <title>dynamic system demo</title> <script> Begin_txt_size=0; End_txt_size=200; txt1=200; txt2=0; function grow_function() { if(Begin_txt_size<End_txt_size) { msg.style.fontSize=Begin_txt_size; Begin_txt_size++; timer=setTimeout("grow_function()",50); }
pg.
63

} function shrink_function() { if(txt1>txt2) { msg.style.fontSize=txt1; txt1--; timer=setTimeout("shrink_function()",50); } function stoptimer(); { clearTimeOut(timer); } </sript> </head> <body> <form name="form1"> <input type="button" name="button1" value="grow" onclick="shrink_function()"> </form>
pg.
64

<p id="msg">Wonderful text effects</p> </body></html> Outout:

pg.

65

Pgm no:14 Date: Aim: write an html program for simple example of servlet SampleServlet.java import javax.servlet.http.*; import javax.servlet.*; import java.io.IOException; import java.io.PrintWriter; public class SampleServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response)throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out=response.getWriter(); out.println("<html><body>");
pg.
66

out.println("<font size='+2' color='green' face='Times New Roman'>"); out.println("Welcome to SampleServlet Example"); out.println("</font></body></html>"); out.close(); web.xml <?xml version="1.0" encoding="ISO-8859-1"?> <!-Copyright 2004 The Apache Software Foundation }}

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software

pg.

67

distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -->

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

<servlet> <servlet-name>SampleServlet</servlet-name> <servlet-class>SampleServlet</servlet-class> </servlet>

pg.

68

<servlet-mapping> <servlet-name>SampleServlet</servlet-name> <url-pattern>/SampleServlet</url-pattern> </servlet-mapping>

</web-app>

Output

pg.

69

pg.

70

Pgm no:15 Date: Aim: write a program for Session Tracking using HttpSession Session.html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>session tracking </title> </head> <body> <form name="form1" method="get" action="./Setsession"> <h3> Username:</h3> <input type="text" name="user"> <h3>password:</h3> <input type="password" name="pwd"> <input type=submit value="submit"> </form> </body>
pg.
71

</html>

GetSessionExample.java import javax.servlet.*; import javax.servlet.http.*; import java.io.*;

public class GetSessionExample extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response)throws IOException,ServletException { response.setContentType("text/html"); PrintWriter out=response.getWriter();

HttpSession session=request.getSession(); String user=(String)session.getAttribute("user"); String pwd=(String)session.getAttribute("pwd");

pg.

72

out.println("<html><body><h1 align='center'>"); out.println("username : "+user+"<br>password :"+pwd); out.println("</h1></body></html>"); out.close(); }

SetSessionExample.java import javax.servlet.*; import javax.servlet.http.*; import java.io.*;

public class SetSessionExample extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response)throws IOException,ServletException { response.setContentType("text/html");
pg.
73

PrintWriter out=response.getWriter();

String user=request.getParameter("user"); String pwd=request.getParameter("pwd");

HttpSession session=request.getSession(); session.setAttribute("user",user); session.setAttribute("pwd",pwd);

out.println("<html><body><h1 align='center'>"); out.println("Session is added"); out.println("</h1></body></html>"); out.close(); }

Web.html <?xml version="1.0" encoding="ISO-8859-1"?> <!-pg.


74

Copyright 2004 The Apache Software Foundation

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -->

<!DOCTYPE web-app
pg.
75

PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

<servlet> <servlet-name>setsession</servlet-name> <servlet-class>SetSessionExample</servlet-class> </servlet>

<servlet-mapping> <servlet-name>setsession</servlet-name> <url-pattern>/Setsession</url-pattern> </servlet-mapping>

<servlet> <servlet-name>getsession</servlet-name> <servlet-class>GetSessionExample</servlet-class> </servlet>


pg.
76

<servlet-mapping> <servlet-name>getsession</servlet-name> <url-pattern>/Getsession</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>/session.html</welcome-file> </welcome-file-list> </web-app> Outout:

pg.

77

Pgm no:16 Date: Aim: write a program for session tracking using cookies Cookie.html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>cookies</title> </head>
pg.
78

<body> <form name="form1" method="get" action="./Setcookie"> <h3> Username:</h3> <input type="text" name="user"> <h3>password:</h3> <input type="password" name="pwd"> <input type=submit value="submit"> </form> </body> </html>

GetCookieExample.java import javax.servlet.*; import javax.servlet.http.*; import java.io.*;

public class GetCookieExample extends HttpServlet {

pg.

79

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

Cookie c[]=request.getCookies(); out.println("<html><body><h1 align='center'>"); for(int i=0;i<c.length; i++) { out.println(c[i].getName()+":"+c[i].getValue() +"<br>"); } out.println("</h1></body></html>"); out.close(); }

SetCookieExample.java
pg.
80

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

public class SetCookieExample extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response)throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out=response.getWriter(); String user=request.getParameter("user"); String pwd=request.getParameter("pwd");

Cookie c1=new Cookie("user",user); Cookie c2=new Cookie("pwd",pwd); response.addCookie(c1); response.addCookie(c2);

pg.

81

out.println("<html><body><h1 align='center'>"); out.println("New Cookie is added"); out.println("</h1></body></html>"); out.close(); }

Web.xml <?xml version="1.0" encoding="ISO-8859-1"?> <!-Copyright 2004 The Apache Software Foundation

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
pg.
82

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -->

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

<servlet> <servlet-name>setcookie</servlet-name>
pg.
83

<servlet-class>SetCookieExample</servlet-class> </servlet>

<servlet-mapping> <servlet-name>setcookie</servlet-name> <url-pattern>/Setcookie</url-pattern> </servlet-mapping>

<servlet> <servlet-name>getcookie</servlet-name> <servlet-class>GetCookieExample</servlet-class> </servlet>

<servlet-mapping> <servlet-name>getcookie</servlet-name> <url-pattern>/Getcookie</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>/cookie.html</welcome-file> </welcome-file-list></web-app>


pg.
84

Output

pg.

85

You might also like