Download - Web Technology Lab Excercise
-
7/29/2019 Web Technology Lab Excercise
1/65
1)HOME PAGE:
The static home page must contain three frames.
Top frame: Logo and the college name and links to Home page, Login page,Registration page,Catalogue page and Cart page (the description of these pages will
be given below).
Left frame: At least four links for navigation, which will display the catalogue of
respective links.For e.g.: When you click the link CSE the catalogue for CSE Books
should be displayed in the Right frame.
Right frame: The pages to the links in the left frame must be loaded here. Initially
this page contains Description of the web site.
2) LOGIN PAGE:
3) CATOLOGUE PAGE:
The catalogue page should contain the details of all the books available in the web
site in a table.
The details should contain the following:
1. Snap shot of Cover Page.
2. Author Name.3. Publisher.4. Price.5. Add to cart button.
4) CART PAGE:
The cart page contains the details about the books which are added to the cart.
The cart page should look like this:
1
Program No: 1
Date: / /2013
Develop static pages (using only html) of an online,
book store. The website should consist of
-
7/29/2019 Web Technology Lab Excercise
2/65
PROGRAM:
Index.html
Welcome to AMAZON Ebook's website
Top.html
Welcome to AMAZON website
td{
cursor:pointer; color: #000066; font-weight:bolder; border:#665599 1solid ; }
marquee{background: #556677; color:#f5f5f5}
2
-
7/29/2019 Web Technology Lab Excercise
3/65
WORLD BEST ONLINE EBOOKS WEBSITE
Home
Login
Registration
Catalogue
Cart
left.html
CSE
ECE
Style.css
h3{color: #006699; font-family: Geneva, Arial, Helvetica, sans-serif;} p
{color: #003366;}
td{color: #003366;} th{color:#FFFFFF;} body{background-
color:#F6F6F0;}
3
-
7/29/2019 Web Technology Lab Excercise
4/65
right.html
Welcome to Amazon Website
Shopping at AMAZON can be both fun and savings.Shop with us
in this special discount season and save upto 50% on all your purchases.
(C) 2008 All rights reserved by Amazon ebooks
Login.html
Welcome to AMAZON website
Enter Login Details
User ID
4
-
7/29/2019 Web Technology Lab Excercise
5/65
Password
Forgot my User ID or Password
Registration.html
Welcome to AMAZON website
Registration Form
Name:*
5
-
7/29/2019 Web Technology Lab Excercise
6/65
Password:*
Email ID:*
Phone Number:*
Gender:*
Male
Female
Date of Birth:*
dd:
for(i=1;i
-
7/29/2019 Web Technology Lab Excercise
7/65
Language Known:*
English
-
7/29/2019 Web Technology Lab Excercise
8/65
Price
Options
Title: Office 2007 Server
Author: RajaPublicher:Tata Mc.Grawhill
Rs. 1200/-
Book: Electronics Projects
Author: Robert TomPublic: Indian Ebook Mfg.
Rs. 1000/-Book: Solar Power Your Home
Author: AlbertPublicher: Andhra Mc.hill
Rs. 9000/-For more ebooks catagory, visit side panel links
Cart.html
8
-
7/29/2019 Web Technology Lab Excercise
9/65
Cart
BookName
Price
Quantity
Amount
Office 2007 Server
Rs. 1200/-
2
Rs. 2400/-
Solar Power Your Home
Rs. 9000/-
1
Rs. 9000/-
Total
Amount:
3
Rs. 11400/-
9
-
7/29/2019 Web Technology Lab Excercise
10/65
Continue
Shopping...
CSE.html
Computer Science & Engineering Catalogue
BOOK
DETAILS
PRICE
OPTION
Title: Office 2007 Server
Author: B.R.Prathap
Publicher:Tata Mc.GrawhillRs. 1200/-
10
-
7/29/2019 Web Technology Lab Excercise
11/65
Title: Electronics Projects
Author: Prathapr
Publicher:Tata Mc.GrawhillRs. 1000/-
Title: Solar Power Your Home
Author:Jhanaki Ramaya Sir
Publicher:Tata Mc.GrawhillRs. 9000/-
ECE.html
Electronics Communication Engineering Catalogue
11
-
7/29/2019 Web Technology Lab Excercise
12/65
BOOK
DETAILS
PRICE
OPTION
Book: Electronics Projects
Author: RobertTom
Public: Indian Ebook Mfg.
Rs. 1000/-
Book: Digital Communication System
Author:Howel AlbertPublic: Tata Mc.Grawhill
Rs. 1000/-
Book: Digital and Analog Communications
Author:Weinberg
Public: Tata Mc.Grawhill
Rs 1200/-
12
-
7/29/2019 Web Technology Lab Excercise
13/65
EEE.html
Eletrical & Electronics Engineering Catalogue
BOOK
DETAILS
PRICE
OPTION
Book:IntelMicroProcessors
Author:HibertSchildt
Publicher: Hyberabad Books Corp.
Rs. 2100/-
13
-
7/29/2019 Web Technology Lab Excercise
14/65
Book: Electrical & Electronics
Author: RamaKrishna. K
Publicher:Tata Mc.Grawhill
Rs. 1250/-
Book: Solar Power Your Home
Author: AlbertPublicher: Andhra Mc.hill
Rs 9000/-
Index.html Output:
14
-
7/29/2019 Web Technology Lab Excercise
15/65
Output:
15
-
7/29/2019 Web Technology Lab Excercise
16/65
Output:
16
-
7/29/2019 Web Technology Lab Excercise
17/65
Output:
Output:
17
-
7/29/2019 Web Technology Lab Excercise
18/65
PROGRAM:
Validation.js
function form1_validation()
{
//Username Validation
if(f1.username.value=="")
{
alert("You must enter a User Name");
f1.username.focus();
return false;
}
if(f1.username.value.length
-
7/29/2019 Web Technology Lab Excercise
19/65
//Password Validation
if(f1.password.value.length
-
7/29/2019 Web Technology Lab Excercise
20/65
flag=false;
if(!(flag))
{
alert("Please enter a valid Email ID");
f1.email.focus();
return false;
}
//phone number validation
flag=true;
if(f1.phno.value.length!=10)
flag=false;
var phno=f1.phno.value;
for(i=0;i=48&&phno.charCodeAt(i)
-
7/29/2019 Web Technology Lab Excercise
21/65
return false;
}
//Date of birth validation
if((f1.dd.selectedIndex
-
7/29/2019 Web Technology Lab Excercise
22/65
{
var validchars = "[email protected]_";
for (i=0; i < email.length; i++)
{
var letter = email.charAt(i).toLowerCase();
if (validchars.indexOf(letter) == -1)
return false;
} return true;
}
Login.html
Welcome to AMAZON website
Enter Login Details
User ID
Password
22
-
7/29/2019 Web Technology Lab Excercise
23/65
Forgot my User ID or Password
Registration.html
Welcome to AMAZON website
Registration Form
Name:*
Password:*
Email ID:*
Phone Number:*
Gender:*
Male
Female
Date of Birth:*
dd:
23
-
7/29/2019 Web Technology Lab Excercise
24/65
for(i=1;i
-
7/29/2019 Web Technology Lab Excercise
25/65
25
-
7/29/2019 Web Technology Lab Excercise
26/65
26
-
7/29/2019 Web Technology Lab Excercise
27/65
27
-
7/29/2019 Web Technology Lab Excercise
28/65
28
-
7/29/2019 Web Technology Lab Excercise
29/65
PAGE:
PROGRAM:
Font Test
Font Check
AllOperations
Bold italic checkOUTPUT:
Font Check
All Operations
Bold italic check
29
Program No: 3
Date: / /2013
Program for implementation of Fonts
-
7/29/2019 Web Technology Lab Excercise
30/65
AGE:
PROGRAM:
Using Tables
Student Marks
Name
Marks
alok
90
anuj
90
ankush
30
Program No: 4
Date: / /2013
Program for creating a table
-
7/29/2019 Web Technology Lab Excercise
31/65
90
Avg Marks
90
OUTPUT:
Student Marks
Name Marks
pratha
p90
rames
h90
prabhu 90
Avg 90
31
-
7/29/2019 Web Technology Lab Excercise
32/65
OME PAGE:
PROGRAM:
event clicking
function passwordCheck()
{
var pw=ole.pw.value;
var cpw=ole.cpw.value;
if(pw!=cpw)
window.alert("Re-enter your password");
}
PASSWORD:&nb
sp;
CONFIRMPASSWORD
32
Program No: 5
Date: / /2013
Program for Entering a password
-
7/29/2019 Web Technology Lab Excercise
33/65
OUTPUT:
33
-
7/29/2019 Web Technology Lab Excercise
34/65
ME PAGE:
PROGRAM:
student.dtd:
student.xsd:
34
Program No: 6
Date: / /2013
Create and save an XML document at the server,
which contains 10 users information. Write a program
which takes User Id as input and returns the user
-
7/29/2019 Web Technology Lab Excercise
35/65
35
-
7/29/2019 Web Technology Lab Excercise
36/65
student.xml:
-
08A01D2501
-
A
Aruna
-
Venkateswara
Rao
software engineering
1ST Year
-
32-15/1-44
B.R.Nagar-1
Hyderabad
9949643372
36
http://c/Documents%20and%20Settings/Administrator.HOME-2E3171E588/Local%20Settings/Temp/Rar$DI24.953/http://c/Documents%20and%20Settings/Administrator.HOME-2E3171E588/Local%20Settings/Temp/Rar$DI24.953/http://c/Documents%20and%20Settings/Administrator.HOME-2E3171E588/Local%20Settings/Temp/Rar$DI24.953/http://c/Documents%20and%20Settings/Administrator.HOME-2E3171E588/Local%20Settings/Temp/Rar$DI24.953/http://c/Documents%20and%20Settings/Administrator.HOME-2E3171E588/Local%20Settings/Temp/Rar$DI24.953/http://c/Documents%20and%20Settings/Administrator.HOME-2E3171E588/Local%20Settings/Temp/Rar$DI24.953/http://c/Documents%20and%20Settings/Administrator.HOME-2E3171E588/Local%20Settings/Temp/Rar$DI24.953/http://c/Documents%20and%20Settings/Administrator.HOME-2E3171E588/Local%20Settings/Temp/Rar$DI24.953/ -
7/29/2019 Web Technology Lab Excercise
37/65
08A01D2501
-
Prathap
Rudra
-
Venkateswara
B
software engineering (mtech)
1st Year
-
door no 603/n
Recoloney
Vijayawada
9866145423
08A01D2503
-
Ramesh
Kumar
-
Venkateswara
Rao
software engineering(mtech)
1st Year37
http://c/Documents%20and%20Settings/Administrator.HOME-2E3171E588/Local%20Settings/Temp/Rar$DI24.953/http://c/Documents%20and%20Settings/Administrator.HOME-2E3171E588/Local%20Settings/Temp/Rar$DI24.953/http://c/Documents%20and%20Settings/Administrator.HOME-2E3171E588/Local%20Settings/Temp/Rar$DI24.953/http://c/Documents%20and%20Settings/Administrator.HOME-2E3171E588/Local%20Settings/Temp/Rar$DI24.953/http://c/Documents%20and%20Settings/Administrator.HOME-2E3171E588/Local%20Settings/Temp/Rar$DI24.953/http://c/Documents%20and%20Settings/Administrator.HOME-2E3171E588/Local%20Settings/Temp/Rar$DI24.953/http://c/Documents%20and%20Settings/Administrator.HOME-2E3171E588/Local%20Settings/Temp/Rar$DI24.953/http://c/Documents%20and%20Settings/Administrator.HOME-2E3171E588/Local%20Settings/Temp/Rar$DI24.953/http://c/Documents%20and%20Settings/Administrator.HOME-2E3171E588/Local%20Settings/Temp/Rar$DI24.953/http://c/Documents%20and%20Settings/Administrator.HOME-2E3171E588/Local%20Settings/Temp/Rar$DI24.953/ -
7/29/2019 Web Technology Lab Excercise
38/65
-
32-15/1-44
B.R.Nagar-1
Hyderabad
9985150379
08A01D2504
-
kishore
Galla
-
Venkateswara
Rao
software engineering (mtech)
1st Year
-
32-15/1-44
B.R.Nagar-1
hyderabad
990837394
08A01D2505
-
Madhu
Garlapati38
http://c/Documents%20and%20Settings/Administrator.HOME-2E3171E588/Local%20Settings/Temp/Rar$DI24.953/http://c/Documents%20and%20Settings/Administrator.HOME-2E3171E588/Local%20Settings/Temp/Rar$DI24.953/http://c/Documents%20and%20Settings/Administrator.HOME-2E3171E588/Local%20Settings/Temp/Rar$DI24.953/http://c/Documents%20and%20Settings/Administrator.HOME-2E3171E588/Local%20Settings/Temp/Rar$DI24.953/http://c/Documents%20and%20Settings/Administrator.HOME-2E3171E588/Local%20Settings/Temp/Rar$DI24.953/http://c/Documents%20and%20Settings/Administrator.HOME-2E3171E588/Local%20Settings/Temp/Rar$DI24.953/http://c/Documents%20and%20Settings/Administrator.HOME-2E3171E588/Local%20Settings/Temp/Rar$DI24.953/http://c/Documents%20and%20Settings/Administrator.HOME-2E3171E588/Local%20Settings/Temp/Rar$DI24.953/http://c/Documents%20and%20Settings/Administrator.HOME-2E3171E588/Local%20Settings/Temp/Rar$DI24.953/http://c/Documents%20and%20Settings/Administrator.HOME-2E3171E588/Local%20Settings/Temp/Rar$DI24.953/ -
7/29/2019 Web Technology Lab Excercise
39/65
-
Venkateswara
Rao
software engineering (mtech)
1st Year
-
32-15/1-44
B.R.Nagar-1
Hyderabad
9908005778
39
Program No: 7
Date: / /2013
Bean Assignments
http://c/Documents%20and%20Settings/Administrator.HOME-2E3171E588/Local%20Settings/Temp/Rar$DI24.953/http://c/Documents%20and%20Settings/Administrator.HOME-2E3171E588/Local%20Settings/Temp/Rar$DI24.953/http://c/Documents%20and%20Settings/Administrator.HOME-2E3171E588/Local%20Settings/Temp/Rar$DI24.953/http://c/Documents%20and%20Settings/Administrator.HOME-2E3171E588/Local%20Settings/Temp/Rar$DI24.953/ -
7/29/2019 Web Technology Lab Excercise
40/65
1
a. Create a JavaBeans which gives the exchange value of INR (Indian Rupees) intoequivalent American/Canadian/Australian Dollar value.
b. Create a simple Bean with a label which is the count of number of clicks. Thencreate a Bean info class such that only the count properly is visible in theproperty Window.
c. Create two Beans a) Keypad b) Display pad. After that integrate the two Beansto make it work as a calculator.
d. Create two Beans Traffic Light(implemented as a label with only threebackground colors-red, green, yellow) and Automobile(Implemented as a TextBox which states its state/movement). The state of the Automobile shoulddepend on the following Light Transition table.
Developing a Simple Bean Using the BDK:
This section presents an example that shows how to develop a simple Bean
and connect it to other components via the BDK. Our new component is called theColors Bean. It appears as either a rectangle or ellipse that is filled with a color. A
color is chosen at random when the Bean begins execution. A public method can be
invoked to change it. Each time the mouse is clicked on the Bean, another random
color is chosen. There is one boolean read/write property that determines the shape.
The BDK is used to lay out an application with one instance of the Colors Bean and
one instance of the OurButton Bean. The button is labeled Change. Each time it is
pressed, the color changes. DEVELOPMENT
USING JAVA
Create a New Bean
Here are the steps that you must follow to create a new Bean:
1. Create a directory for the new Bean.
2. Create the Java source file(s).
3. Compile the source file(s).
4. Create a manifest file.
5. Generate a JAR file.
6. Start the BDK.
7. Test.
The following sections discuss each of these steps in detail.
Create a Directory for the New Bean You need to make a directory for theBean. To follow along with this example, create c:\bdk\demo\sunw\demo\colors.
Then change to that directory. The Colors and OurButton Beans Create the Source File40
-
7/29/2019 Web Technology Lab Excercise
41/65
for the New Bean The source code for the Colors component is shown in the following
listing. It is located in the file Colors.java. The import statement at the beginning of
the file places it in the package named sunw.demo.colors. Recall from Chapter 9
that the directory hierarchy corresponds to the package hierarchy. Therefore, this file
must be located in a subdirectory named sunw\demo\colors relative to the
CLASSPATH environment variable. The color of the component is determined by the
private Color variable color, and its shape is determined by the private boolean
variable rectangular. The constructor defines an anonymous inner class that extends
MouseAdapter and overrides its mousePressed( ) method. The change( ) method
is invoked in response to mouse presses. The component is initialized to a rectangular
shape of 200 by 100 pixels. The change( ) method is invoked to select a random
color and repaint the component. The getRectangular( ) and setRectangular( )
methods provide access to the one property of this Bean. The change( ) method calls
randomColor( ) to choose a color and then calls repaint( ) to make the change
visible. Notice that the paint( ) method uses the rectangular and color variables to
determine how to present the Bean.
// A simple Bean.
package sunw.demo.colors;
import java.awt.*;
import java.awt.event.*;
public class Colors extends Canvas {
transient private Color color;
private boolean rectangular;
public Colors() {
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent me) {
change();
}
});
rectangular = false;
setSize(200, 100);
change();
}
41
-
7/29/2019 Web Technology Lab Excercise
42/65
public boolean getRectangular() {
return rectangular;
}
public void setRectangular(boolean flag) {
this.rectangular = flag;
repaint();
}
public void change()
{
color = randomColor();
repaint();
}
private Color randomColor() {
int r = (int)(255*Math.random());
int g = (int)(255*Math.random());
int b = (int)(255*Math.random());
return new Color(r, g, b);
}
public void paint(Graphics g) {
Dimension d = getSize();
int h = d.height;
int w = d.width;
g.setColor(color);
if(rectangular) {
g.fillRect(0, 0, w-1, h-1);
}
else {
g.fillOval(0, 0, w-1, h-1);
}42
-
7/29/2019 Web Technology Lab Excercise
43/65
}
}
Compile the Source Code for the New Bean Compile the source code to create a class
file. Type the following:
javac Colors.java.
Create a Manifest File You must now create a manifest file. First, switch to the
c:\bdk\demo directory. This is the directory in which the manifest files for the BDK
demos are located. Put the source code for your manifest file in the file colors.mft.
It is shown here:
Name: sunw/demo/colors/Colors.class
Java-Bean: True
This file indicates that there is one .class file in the JAR file and that it is a Java
Bean Notice that the Colors.class file is in the package sunw.demo.colors and in
the subdirectory sunw\demo\colors relative to the current directory. Generate a JAR
File Beans are included in the ToolBox window of the BDK only if they are in JAR filesin the directory c:\bdk\jars. These files are generated with the jar utility.
Enter the following:
jar cfm ..\jars\colors.jar colors.mft sunw\demo\colors\*.class
This command creates the file colors.jar and places it in the directory c:\bdk\jars.
(You may wish to put this in a batch file for future use.)
Start the BDK Change to the directory c:\bdk\beanbox and type run. This
causes the BDK to start. You should see three windows, titled ToolBox, BeanBox, and
Properties. The ToolBox window should include an entry labeled Colors for your new
Bean. Create an Instance of the Colors Bean After you complete the preceding steps,
create an instance of the Colors Bean in the BeanBox window. Test your new
component by pressing the mouse anywhere within its borders. Its color immediately
changes. Use the Properties window to change the rectangular property from falseto true. Its shape immediately changes.
43
-
7/29/2019 Web Technology Lab Excercise
44/65
Create and Configure an Instance of the OurButton Bean Create an instance of the
OurButton Bean in the BeanBox window. Then follow these steps:
1. Go to the Properties window and change the label of the Bean to Change. You
should see that the button appearance changes immediately when this property is
changed.
2. Go to the menu bar of the BeanBox and select Edit | Events | action |
actionPerformed.
3. Move the cursor so that it is inside the Colors Bean display area, and click the left
mouse button. You should see the Event Target Dialog dialog box.
4. The dialog box allows you to choose a method that should be invoked when this
button is clicked. Select the entry labeled change and click the OK button.You
should see a message box appear very briefly, stating that the tool isGenerating and
compiling adaptor class.
5. Click on the button. You should see the color change. You might want to
experiment with the Colors Bean a bit before moving on.
OUTPUT:
44
-
7/29/2019 Web Technology Lab Excercise
45/65
PROGRAM:
/**/
import java.awt.*;
import java.lang.String;
import java.awt.event.*;
import java.applet.Applet;
import java.applet.*;
public class Sig extends Applet implements ItemListener{
boolean c1,c2,c3;
String s1;
Checkbox r1,r2,r3;
CheckboxGroup cbg;
public void init(){
cbg=new CheckboxGroup();
Panel p=new Panel();
p.setLayout(new GridLayout());
add(r1=new Checkbox("red",cbg,false));
add(r2=new Checkbox("yellow",cbg,false));
add(r3=new Checkbox("green",cbg,false));
r1.addItemListener(this);
r2.addItemListener(this);
r3.addItemListener(this);
}
public void paint(Graphics g) {
g.setColor(Color.red);
45
Create two Beans Traffic Light(implemented as a label with only three
background colors-red, green, yellow) and Automobile(Implemented as a Text
Box which states its state/movement). The state of the Automobile should
-
7/29/2019 Web Technology Lab Excercise
46/65
g.drawOval(10, 30, 20, 20);
//System.out.println(s1);
g.setColor(Color.yellow);
g.drawOval(10, 60, 20, 20);
g.setColor(Color.green);
g.drawOval(10, 90, 20, 20);
s1=cbg.getSelectedCheckbox().getLabel();
if(s1=="red")
{
g.setColor(Color.red);
g.fillOval(10, 30, 20, 20);
}
else if(s1=="yellow")
{
g.setColor(Color.yellow);
g.fillOval(10, 60, 20, 20);
}
else if(s1=="green")
{
g.setColor(Color.green);
g.fillOval(10, 90, 20, 20);
}
}
public void itemStateChanged(ItemEvent ie) {
repaint();
}
}
46
Program No: 8
SERVELETS & COOKIES
-
7/29/2019 Web Technology Lab Excercise
47/65
Reading Servlet Parameters:
The ServletRequest class includes methods that allow you to read the names and
values of parameters that are included in a client request. We will develop a servlet
that illustrates their use. The example contains two files: PostParameters.htm
defines a Web page, and PostParametersServlet.java defines a servlet. The HTML
source code for PostParameters.htm is shown in the following listing. It defines a
table that contains two labels and two text fields. One of the labels is Employee and
the other is Phone. The form also includes a submit button. Notice that the action
parameter of the form tag specifies a URL. The URL identifies the servlet to process
the HTTP POST request.
Employee
Phone
47
Date: / /2013
-
7/29/2019 Web Technology Lab Excercise
48/65
The source code for PostParametersServlet.java is shown in the following listing.
The service( ) method is overridden to process client requests. The
getParameterNames( ) method returns an enumeration of the parameter names.
These are processed in a loop. You can see that the parameter name and value are
output to the client. The parameter value is obtained via the getParameter( )
method.
import java.io.*;
import java.util.*;
import javax.servlet.*;
public class PostParametersServlet
extends GenericServlet {
public void service(ServletRequest request,
ServletResponse response)
throws ServletException, IOException {
// Get print writer
PrintWriter pw = response.getWriter();
// Get enumeration of parameter names
Enumeration e = request.getParameterNames();
// Display parameter names and values
while(e.hasMoreElements()) {
String pname = (String)e.nextElement();
pw.print(pname + " = ");
String pvalue = request.getParameter(pname);
pw.println(pvalue);
}
pw.close();
}
}
48
-
7/29/2019 Web Technology Lab Excercise
49/65
The example contains two files: ColorGet.htm defines a Web page, and
ColorGetServlet.java defines a servlet. The HTML source code for ColorGet.htm is
shown in the following listing. It defines a form that contains a select element and a
submit button. Notice that the action parameter of the form tag specifies a URL. The
URL identifies a servlet to process the HTTP GET request.
Color:
Red
Green
Blue
method is overridden to process any HTTP GET requests that are sent to this servlet. It
uses the getParameter( ) method ofHttpServletRequest to obtain the selection
that was made by the user. A response is then formulated.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ColorGetServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
49
-
7/29/2019 Web Technology Lab Excercise
50/65
String color = request.getParameter("color");
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("The selected color is: ");
pw.println(color);
pw.close();
The HTML source code for ColorPost.htm is shown in the following listing. It is
identical to ColorGet.htm except that the method parameter for the form tag
explicitly specifies that the POST method should be used, and the action parameter
for the form tag
specifies a different servlet.
Color:
Red
Green
Blue
50
-
7/29/2019 Web Technology Lab Excercise
51/65
The source code for ColorPostServlet.java is shown in the following listing. The
doPost( ) method is overridden to process any HTTP POST requests that are sent to
this servlet. It uses the getParameter( ) method ofHttpServletRequest to obtain
the selection that was made by the user. A response is then formulated.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ColorPostServlet extends HttpServlet {
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
String color = request.getParameter("color");
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("The selected color is: ");
pw.println(color);
pw.close();
}
}
Source Code for functions.jsp
JSP 2.0 Expression Language - Functions
JSP 2.0 Expression Language - Functions
An upgrade from the JSTL expression language, the JSP 2.0 EL also allows for simple
function invocation. Functions are defined by tag libraries and are implemented by aJava programmer as static methods.
Change Parameter
foo =
51
http://localhost:8080/jsp-examples/jsp2/el/functions.jsp.htmlhttp://localhost:8080/jsp-examples/jsp2/el/functions.jsp.html -
7/29/2019 Web Technology Lab Excercise
52/65
EL ExpressionResult
\${param["foo"]}${fn:escapeXml(param["foo"])}
\${my:reverse(param["foo"])}${my:reverse(fn:escapeXml(param["foo"]))}
\${my:reverse(my:reverse(param["foo"]))}
${my:reverse(my:reverse(fn:escapeXml(param["foo"])))}\${my:countVowels(param["foo"])}${my:countVowels(fn:escapeXml(param["foo"]))}
Source Code for Calendar Example
Calendar: A JSP APPLICATION
52
-
7/29/2019 Web Technology Lab Excercise
53/65
prev Calendar: next
Time Appointment
-
7/29/2019 Web Technology Lab Excercise
54/65
Calender2
Calendar: A JSP APPLICATION
Please add the following event:
Date
Time
-
7/29/2019 Web Technology Lab Excercise
55/65
Source Code for Servlet calling JSP
import javax.servlet.*;import javax.servlet.http.*;
public class servletToJsp extends HttpServlet {
public void doGet (HttpServletRequest request,HttpServletResponse response) {
try {// Set the attribute and Forward to hello.jsprequest.setAttribute ("servletName", "servletToJsp");
getServletConfig().getServletContext().getRequestDispatcher("/jsptoserv/hello.jsp").forward(request, response);
} catch (Exception ex) {ex.printStackTrace ();
}}
}
OUTPUT
I have been invoked by servletToJsp Servlet
Source Code for HelloWorld Example
import java.io.*;import javax.servlet.*;import javax.servlet.http.*;
public class HelloWorld extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{response.setContentType("text/html");
PrintWriter out = response.getWriter();out.println("");out.println("");out.println("Hello World!");out.println("");out.println("");out.println("Hello World!");out.println("");out.println("");
}}
55
http://localhost:8080/jsp-examples/jsptoserv/servletToJsp.java.htmlhttp://localhost:8080/jsp-examples/jsptoserv/servletToJsp.java.html -
7/29/2019 Web Technology Lab Excercise
56/65
OUTPUT:
Hello World!
Source Code for Session Example
import java.io.*;import java.util.*;import javax.servlet.*;import javax.servlet.http.*;
public class SessionExample extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{response.setContentType("text/html");
PrintWriter out = response.getWriter();
HttpSession session = request.getSession(true);
// print session info
Date created = new Date(session.getCreationTime());Date accessed = new Date(session.getLastAccessedTime());out.println("ID " + session.getId());out.println("Created: " + created);out.println("Last Accessed: " + accessed);
// set session info if needed
String dataName = request.getParameter("dataName");if (dataName != null && dataName.length() > 0) {
String dataValue = request.getParameter("dataValue");session.setAttribute(dataName, dataValue);
}
// print session contents
Enumeration e = session.getAttributeNames();while (e.hasMoreElements()) {
String name = (String)e.nextElement();String value = session.getAttribute(name).toString();out.println(name + " = " + value);
}}
}
56
-
7/29/2019 Web Technology Lab Excercise
57/65
OUTPUT
Sessions Example
Session ID: E55B7AE87EEC8556A084BBFF47E96155
Created: Sat feb 14 12:00:08 IST 2009
Last Accessed: Sun Feb 15 12:00:43 IST 2009
The following data is in your session:Prathap = 1234Rudra= 4321
Name of Session Attribute:
Value of Session Attribute:
GET based form:
Name of Session Attribute:
Value of Session Attribute:
57
Submit query
Submit
-
7/29/2019 Web Technology Lab Excercise
58/65
URL Encoded
Using Cookies
Now, let's develop a servlet that illustrates how to use cookies. The servlet is invoked
when a form on a Web page is submitted. The example contains three files, as
summarized here:
File Description
AddCookie.htm Allows a user to specify a value for the cookie named M yCookie
AddCookieServlet.java Processes the submission of
AddCookie.htmGetCookiesServlet.java Displays cookie values The HTML source code
for AddCookie.htm is shown in the following listing. This page contains a text field in
which a value can be entered. The page also includes a submit button. When this
button is pressed, the value in the text field is sent to AddCookieServlet via an HTTP
POST request.
Enter a value for MyCookie:
The source code for AddCookieServlet.java is shown in the following listing. It
gets the value of the parameter named "data". It then creates a Cookie object that
has the name "MyCookie" and contains the value of the "data" parameter. The cookie
is then added tothe header of the HTTP response via the addCookie( ) method. Afeedback message is then written to the browser.
58
http://www.gmail.com/http://www.gmail.com/ -
7/29/2019 Web Technology Lab Excercise
59/65
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class AddCookieServlet extends HttpServlet {
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
// Get parameter from HTTP request
String data = request.getParameter("data");
Cookie cookie = new Cookie("MyCookie", data);
// Add cookie to HTTP response
response.addCookie(cookie);
// Write output to browser
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("MyCookie has been set to");
pw.println(data);
pw.close();
}
}
The source code for GetCookiesServlet.java is shown in the following listing. It
invokes the getCookies( ) method to read any cookies that are included in the HTTP
GET request. The names and values of these cookies are then written to the HTTP
response. Observe that the getName( ) and getValue( ) methods are called to
obtain this information.
import java.io.*;
import javax.servlet.*;
59
-
7/29/2019 Web Technology Lab Excercise
60/65
import javax.servlet.http.*;
public class GetCookiesServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
// Get cookies from header of HTTP request
Cookie[] cookies = request.getCookies();
// Display these cookies
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("");
for(int i = 0; i < cookies.length; i++) {
String name = cookies[i].getName();
String value = cookies[i].getValue();
pw.println("name = " + name +
"; value = " + value);
}
pw.close();
}
}
The following servlet illustrates how to use session state. The getSession( )
method gets the current session. A new session is created if one does not already
exist. The getValue( ) method is called to obtain the object that is bound to thename "date". That object is a Date object that encapsulates the date and time when
this page was last accessed. (Of course, there is no such binding when the page is
first accessed.) A Date object encapsulating the current date and time is then
created. The putValue( ) method is called to bind the name "date" to this object.
import java.io.*;
import java.util.*;
import javax.servlet.*;
60
-
7/29/2019 Web Technology Lab Excercise
61/65
import javax.servlet.http.*;
public class DateServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
// Get the HttpSession object
HttpSession hs = request.getSession(true);
// Get writer
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.print("");
// Display date/time of last access
Date date = (Date)hs.getValue("date");
if(date != null) {
pw.print("Last access: " + date + "
");}
// Display current date/time
date = new Date();
hs.putValue("date", date);
pw.println("Current date: " + date);
}}
Source Code for Cookie Example
import java.io.*;import javax.servlet.*;import javax.servlet.http.*;
public class CookieExample extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException{response.setContentType("text/html");
61
-
7/29/2019 Web Technology Lab Excercise
62/65
PrintWriter out = response.getWriter();
// print out cookies
Cookie[] cookies = request.getCookies();for (int i = 0; i < cookies.length; i++) {
Cookie c = cookies[i];String name = c.getName();String value = c.getValue();out.println(name + " = " + value);
}
// set a cookie
String name = request.getParameter("cookieName");if (name != null && name.length() > 0) {
String value = request.getParameter("cookieValue");Cookie c = new Cookie(name, value);
response.addCookie(c);}
}}
OUTPUT:
Cookies Example
Your browser is sending the following cookies:
Cookie Name: Rudra
Cookie Value: 876543
Cookie Name: Prathap
Cookie Value: 1234567
You just sent the following cookie to your browser:Name: Nova
Value: 5000060
Create a cookie to send to your browser
Name:
Value:
62
Pratha
123456
Submit Query
-
7/29/2019 Web Technology Lab Excercise
63/65
:
PROGRAM:
JSP 2.0 Examples - Hello World SimpleTag Handler
JSP 2.0 Examples - Hello World SimpleTag Handler
This tag handler simply echos "Hello, World!" It's an example ofa very basic SimpleTag handler with no body.
Result:OUTPUT:
This tag handler simply echos "Hello, World!" It's an example of a very basic
SimpleTag handler with no body.
Result: Hello, world!
63
Program No: 9
Date: / /2013
Implement the Hello World! program using JSP
Struts Framework. Source Code for the HelloWorld Tag Example
-
7/29/2019 Web Technology Lab Excercise
64/65
GE:
PROGRAM:
MAX
var a,b,c,n1,n2,n3,m1,m2,sum,avg;
a=prompt("enter 1st no="," ");b=prompt("enter 2nd no="," ");c=prompt("enter 3rd no="," ");n1=parseInt(a);n2=parseInt(b);n3=parseInt(c);sum=n1+n2+n3;
avg=sum/3;m1=Math.max(n1,n2);m2=Math.max(n3,m1);
alert("the sum is= "+sum);alert("the avg is= "+m2);alert("the max no is "+m2);
64
Program No: 10
Date: / /2013
Write Java Script that inputs three integers from the
user and outputs their sum, average, largest. Use
alert dialog box to display results.
-
7/29/2019 Web Technology Lab Excercise
65/65
OUTPUT: