World Wide Web has been created to share the

hopeacceptableSoftware and s/w Development

Oct 28, 2013 (3 years and 5 months ago)

66 views


World

Wide

Web

has

been

created

to

share

the

text

document

across

the

world
.


In

static

web

pages

the

requesting

user

has

no

ability

to

interact

with

the

content

delivered

by

the

web

server
.


The

term

dynamic

describes

the

process

of

generating

HTML

pages

according

to

the

information

requested

by

the

user

to

the

web

server
.



Client

Side

Scripting


Scripting

means

the

location

where

the

code

is

processed
.


In

CSS

code

is

processed

at

the

client

side
.


We

embed

client

side

scripting

languages

code

to

the

HTML
.


E
.
g
.

Javascript,Vbscript,Jscript

Advantages

1
.
Work

on

the

server

is

reduced,

since

processing

is

done

at

client

side
.

2
.
Network

traffic

is

reduced
.

3
.
Faster

than

server

side

scripting
.



Disadvantages


1
.
Code

is

completely

visible

to

the

user

and

hence

no

security

to

data
.

Server Side Scripting


Request

is

processed

at

the

server

side
.



Coder

is

protected
.



Server

will

have

additional

workload
.



Comparatively

slow
.


E
.
g
.

CGI/Perl,

JSP,ASP



The

problem

with

CGI

is

that

program

must

be

restarted

for

every

request
.


Sun

Microsystems

introduced

servlet

to

solve

this

problem
.


Servlet

is

a

small

piece

of

code

that

extends

the

functionality

of

a

server
.


Later

JSP

was

introduced
.



Phases

of

a

JSP


Each

JSP

goes

through

2

distinct

phases
.




1
.
Translation

phase/time




2
.
Request

phase/time


At

translation

phase

JSP

engine

turns

JSP

file

into

a

servlet
.



It

happens

whenever

we

modify

a

JSP

file
.



At

Request

phase

servlet

is

run

to

generate

the

required

page
.


Handling

of

comments

happens

at

translation

phase
.

JSP

Processing

The

following

steps

explain

how

the

web

server

creates

the

web

page

using

JSP
:


As

with

a

normal

page,

your

browser

sends

an

HTTP

request

to

the

web

server
.


The

web

server

recognizes

that

the

HTTP

request

is

for

a

JSP

page

and

forwards

it

to

a

JSP

engine
.

This

is

done

by

using

the

URL

or

JSP

page

which

ends

with

.
jsp

instead

of

.
html
.



The

JSP

engine

loads

the

JSP

page

from

disk

and

converts

it

into

a

servlet

content
.

This

conversion

is

very

simple

in

which

all

template

text

is

converted

to

println
(

)

statements

and

all

JSP

elements

are

converted

to

Java

code

that

implements

the

corresponding

dynamic

behavior

of

the

page
.



The

JSP

engine

compiles

the

servlet

into

an

executable

class

and

forwards

the

original

request

to

a

servlet

engine
.


A

part

of

the

web

server

called

the

servlet

engine

loads

the

Servlet

class

and

executes

it
.

During

execution,

the

servlet

produces

an

output

in

HTML

format,

which

the

servlet

engine

passes

to

the

web

server

inside

an

HTTP

response
.




The

web

server

forwards

the

HTTP

response

to

your

browser

in

terms

of

static

HTML

content
.


Finally

web

browser

handles

the

dynamically

generated

HTML

page

inside

the

HTTP

response

exactly

as

if

it

were

a

static

page
.




In order to execute a
jsp

page we have 2
requirements.

1.Java should be installed.

2.Webserver should be installed.


E.g.
Tomcat,Weblogic,Websphere





Building blocks of JSP

1.JSP expressions

2.JSP scriplets

3.JSP declarations


JSP

expression



It

has

the

following

form

<
%
=java

expression
%
>


It

is

used

to

insert

java

values

directly

into

the

output
.


Java

expression

is

evaluated,

converted

to

a

string

and

inserted

in

the

page
.



<html>


<head>

<title>A Comment Test</title>

</head>


<body>


<p>


Today's date: <%= (new
java.util.Date
()).
toLocaleString
()%>

</p>

</body>


</html>


Output


Today's date: 05
-
Sep
-
2012 10:24:25

JSP

Comments


JSP

comment

marks

text

or

statements

that

the

JSP

container

should

ignore
.

A

JSP

comment

is

useful

when

you

want

to

hide

or

"comment

out"

part

of

your

JSP

page
.



Following

is

the

syntax

of

JSP

comments
:

<
%
--

This

is

JSP

comment

--
%
>

JSP

declarations


It

takes

the

form

<%! Java code%>


E
.
g
.

<
%
!

int

count=
100
;
%
>


<
%
=

count+
1
%
>

The

browser

will

display

101
.



JSP

declaration

can

contain

many

declarations

but

a

JSP

expression

contains

only

one

expression
.



We can also declare a method in a JSP declaration
and can call it from a JSP expression.


<%!
int

count=100;


int

plusone
(
int

n) {


return n+1;


}

%>

The no: you are looking is<%=
plusone
(count)%>

The no: is still <%=
plusone
(count)%>


Scriplets



It is a piece of Java code sandwiched between the
characters <% and %>



It takes the following form:


<% java code %>




<% if (
Math.random
(),0.5) { %>

Have a <b> nice </b> day!

<% } else { %>

Have a <b>dull </b> day!

<% }%>




<html>


<head>

<title>Hello World</title>

</head>


<body>

Hello World!<
br
/> <%
out.println
("Your IP address
is " +
request.getRemoteAddr
()); %>

</body>

</html>

Declaration

Scriplet

Expression

Enclosed in

<%!..........%>

<%........%>

<%=………%>

Con瑡tns

One

or more java
declara瑩ons or
me瑨od defini瑩ons

J慶愠
code(condi瑩on
cUecking,loops

e瑣)

One java
expression

坨慴ai琠does

Crea瑥s a name
possibly gives 瑨e
name a value

Tells 瑨e sys瑥m 瑯
do some瑨ing

Has a value

坨en 瑨e JS倠
con瑡tner runs it

坨en page is 1
st

visited or the JSP
container reinitializes
the page

Whenever
someone visits

the
page

Whenever
someone visits

the
page

Request

and

Response

Objects



When

we

receive

a

request

from

a

user,

we

can

get

information

about

that

request

by

calling

methods

associated

with

the

implicit

request

object
.


When

you

prepare

a

response,

we

can

set

the

characteristics

of

the

response

b

calling

methods

associated

with

the

implicit

response

object
.


Methods of request object are:

1.
getHeader
()

(i)
Browser your are using is
<%=
request.getHeader
(“User
-
Agent”)%>


(ii)
Cookie information stored is
<%=
request.getHeader
(“Cookie”)%>


(iii)
Your browser is willing to accept the following
MIME types <%=
request.getHeader
(“Accept”)%>


2.
getMethod
()

(
i
) Method used for sending request is
<%=
request.getMethod
()%>


3.
getRemoteAddr()

(
i
) IP address of the client machine is
<%=
request.getRemoteAddr
()%>


4.
getRemoteHost()

(
i
) DNS name is <%=
request.getRemoteHost
()%>


5.
getLocale
()


(i)
You are from
<%=
request.getLocale.getdisplayCountry
()%>


(ii)
You are using
<%=
request.getLocale.getDisplayLanguage
()%>
language.

Methods of remote object are:


1.
sendRedirect()

<%
response.sendRedirect
(http://abc.com/index.ht
ml);>


2.
sendError()

<%
response.sendError
(404);%>


Forms and request parameters

Login.htm

<html>

<head>

<title>validation</title>

</head>

<body>

<form action="authenticate.jsp" method="GET">

Username<input type=text name=username><
br
>

Password<input type=password name=
pwd
><
br
>

<input type=submit value=submit>

</form>

</body>

</html>





Clicking the Submit button send the following
request:



http://www.abc.com/authenticate.jsp?username=a
bc & password=xyz



authenticate.jsp

<%

If(
request.getParameter
(“
pwd
”).equals (“xyz”)){

%>

<h2> Welcome
<%=
request.getParameter
(“username”)%></h2>

<%

} else {

%>

<%
response.sendError
(403);%>

<% } %>