JSP + Ajax Practice

JSP + Ajax Practice - Practice
problems
 Why Ajax...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Practice
problems
 Why Ajax & Javascript Web
applications
that
involve
Ajax
and
Javascript
have
become
very
common.
Consider
the
following
 possible
reasons
and
mark
which
ones
are
true:
 - YES

NO:
Applications
involving
Ajax
and
Javascript
are
much
easier
to
develop
and
debug
 than
purely
server
side
applications.
 YES

NO:
Applications
involving
Ajax
and
Javascript
tend
to
provide
faster
response
to
user
 clicks
than
purely
server
side
applications.
 YES

NO:
By
combining
Javascript
with
XHR
calls
(Ajax)
an
application
does
not
need
a
 database
any
more.
 Why Servlets Went Out of Fashion Nowadays
very
few
programmers
write
http
servlets
directly
in
Java.
Consider
the
following
possible
 reasons
and
mark
which
ones
are
true:
 - - YES

NO:
Programmers
gave
up
on
writing
servlets
directly
because
jsp’s
run
faster
usually.
 YES

NO:
Programmers
gave
up
on
writing
servlets
directly
because
Tomcat
5.0
(and
many
 other
recent
releases
of
other
application
servers)
have
stopped
supporting
the
kind
of
http
 servlets
we
described
in
class.
 YES

NO:
Programmers
gave
up
on
writing
servlets
once
applet
technology
became
popular.
 Writing Clean JSP Code It
is
very
messy
to
figure
out
what
the
following
jsp
fragment
is
doing.
It
uses
the
implicit
variable
out
 that
explicitly
writes
in
the
body
of
the
http
response
the
HTML
page
that
is
returned
to
the
browser.
 Rewrite
it
in
the
way
that
a
sane
jsp
programmer
would.
 
 <% out.write(“<HTML>”); out.write(“<HEAD><TITLE>foo</TITLE></HEAD>”); out.write(“<BODY> List of Temperatures:”); out.write(“<UL><LI>La Jolla:” + weather(“La Jolla”) + “</LI>”); out.write(“<LI>El Cajon:” + weather(“El Cajon”) + “</LI></UL>”); out.write(“</BODY></HTML>”); /%> 
 
 Session attributes Consider
the
following
JSP
Exam
program

 
 <HTML> <HEAD> <TITLE>Exam</TITLE> </HEAD> <BODY> <% Integer times = (Integer)(session.getAttribute(“times”)) ; if (times == null) { times = new Integer(0) ; } else { times = new Integer(times.intValue() + 1) ; session.setAttribute(“times”, times) ; %> times = <%= times %> </BODY> </HTML> 
 User
A
makes
the
first
access
to
Exam.
The
page
he
receives
back
says
times=0.
Complete
the
 times=___
below,
assuming
the
following
events
happen
in
exactly
the
sequence
described.
 
 
 1. User
A
makes
his
second
access
to
Exam
from
the
same
browser
window.
He
receives
back
 times=____.
 2. User
B
makes
his
first
access
to
Exam
from
another
computer.
He
receives
back
times=____.
 3. User
A
makes
his
third
access
to
Exam
from
yet
another
computer.
He
receives
back
 times=____.
 
 Javascript and AJAX Appropriately
augment
the
following
HTML
page
so
that
as
soon
as
the
user
has
chosen
pink
pants
and
 green
T‐shirt
an
alert
pops
up
with
the
string
“Ridiculous!”
 <html> <head> … </head> <body> <form method=”GET” action=”nowhere.com”> Pants: <select name=”pants”> <option value=”pink”>Pink</option> <option value=”black”>Black</option> </select> <p> T-shirt: <select name=”shirt”> <option value=”green”>Green</option> <option value=”red”>Red</option> </select> </form> </body> </html> <BLANK>
 ...
View Full Document

Ask a homework question - tutors are online