![Page 1: World Wide Web has been created to share the text document across the world](https://reader036.vdocuments.mx/reader036/viewer/2022081604/56816380550346895dd4626a/html5/thumbnails/1.jpg)
• 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.
![Page 2: World Wide Web has been created to share the text document across the world](https://reader036.vdocuments.mx/reader036/viewer/2022081604/56816380550346895dd4626a/html5/thumbnails/2.jpg)
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
![Page 3: World Wide Web has been created to share the text document across the world](https://reader036.vdocuments.mx/reader036/viewer/2022081604/56816380550346895dd4626a/html5/thumbnails/3.jpg)
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.
![Page 4: World Wide Web has been created to share the text document across the world](https://reader036.vdocuments.mx/reader036/viewer/2022081604/56816380550346895dd4626a/html5/thumbnails/4.jpg)
Disadvantages
1.Code is completely visible to the user and hence no security to data.
![Page 5: World Wide Web has been created to share the text document across the world](https://reader036.vdocuments.mx/reader036/viewer/2022081604/56816380550346895dd4626a/html5/thumbnails/5.jpg)
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
![Page 6: World Wide Web has been created to share the text document across the world](https://reader036.vdocuments.mx/reader036/viewer/2022081604/56816380550346895dd4626a/html5/thumbnails/6.jpg)
• 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.
![Page 7: World Wide Web has been created to share the text document across the world](https://reader036.vdocuments.mx/reader036/viewer/2022081604/56816380550346895dd4626a/html5/thumbnails/7.jpg)
Phases of a JSP• Each JSP goes through 2 distinct phases.
1.Translation phase/time2.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.
![Page 8: World Wide Web has been created to share the text document across the world](https://reader036.vdocuments.mx/reader036/viewer/2022081604/56816380550346895dd4626a/html5/thumbnails/8.jpg)
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.
![Page 9: World Wide Web has been created to share the text document across the world](https://reader036.vdocuments.mx/reader036/viewer/2022081604/56816380550346895dd4626a/html5/thumbnails/9.jpg)
• 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.
![Page 10: World Wide Web has been created to share the text document across the world](https://reader036.vdocuments.mx/reader036/viewer/2022081604/56816380550346895dd4626a/html5/thumbnails/10.jpg)
• 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.
![Page 11: World Wide Web has been created to share the text document across the world](https://reader036.vdocuments.mx/reader036/viewer/2022081604/56816380550346895dd4626a/html5/thumbnails/11.jpg)
• 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.
![Page 12: World Wide Web has been created to share the text document across the world](https://reader036.vdocuments.mx/reader036/viewer/2022081604/56816380550346895dd4626a/html5/thumbnails/12.jpg)
![Page 13: World Wide Web has been created to share the text document across the world](https://reader036.vdocuments.mx/reader036/viewer/2022081604/56816380550346895dd4626a/html5/thumbnails/13.jpg)
• 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
![Page 14: World Wide Web has been created to share the text document across the world](https://reader036.vdocuments.mx/reader036/viewer/2022081604/56816380550346895dd4626a/html5/thumbnails/14.jpg)
Building blocks of JSP1.JSP expressions2.JSP scriplets3.JSP declarations
![Page 15: World Wide Web has been created to share the text document across the world](https://reader036.vdocuments.mx/reader036/viewer/2022081604/56816380550346895dd4626a/html5/thumbnails/15.jpg)
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.
![Page 16: World Wide Web has been created to share the text document across the world](https://reader036.vdocuments.mx/reader036/viewer/2022081604/56816380550346895dd4626a/html5/thumbnails/16.jpg)
<html> <head><title>A Comment Test</title></head> <body> <p> Today's date: <%= (new
java.util.Date()).toLocaleString()%> </p> </body> </html>
![Page 17: World Wide Web has been created to share the text document across the world](https://reader036.vdocuments.mx/reader036/viewer/2022081604/56816380550346895dd4626a/html5/thumbnails/17.jpg)
Output
Today's date: 05-Sep-2012 10:24:25
![Page 18: World Wide Web has been created to share the text document across the world](https://reader036.vdocuments.mx/reader036/viewer/2022081604/56816380550346895dd4626a/html5/thumbnails/18.jpg)
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 --%>
![Page 19: World Wide Web has been created to share the text document across the world](https://reader036.vdocuments.mx/reader036/viewer/2022081604/56816380550346895dd4626a/html5/thumbnails/19.jpg)
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.
![Page 20: World Wide Web has been created to share the text document across the world](https://reader036.vdocuments.mx/reader036/viewer/2022081604/56816380550346895dd4626a/html5/thumbnails/20.jpg)
• 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)%>
![Page 21: World Wide Web has been created to share the text document across the world](https://reader036.vdocuments.mx/reader036/viewer/2022081604/56816380550346895dd4626a/html5/thumbnails/21.jpg)
Scriplets
• It is a piece of Java code sandwiched between the characters <% and %>
• It takes the following form: <% java code %>
![Page 22: World Wide Web has been created to share the text document across the world](https://reader036.vdocuments.mx/reader036/viewer/2022081604/56816380550346895dd4626a/html5/thumbnails/22.jpg)
<% if (Math.random(),0.5) { %>Have a <b> nice </b> day!
<% } else { %>Have a <b>dull </b> day!
<% }%>
![Page 23: World Wide Web has been created to share the text document across the world](https://reader036.vdocuments.mx/reader036/viewer/2022081604/56816380550346895dd4626a/html5/thumbnails/23.jpg)
<html> <head>
<title>Hello World</title></head> <body>
Hello World!<br/> <% out.println("Your IP address is " + request.getRemoteAddr()); %>
</body> </html>
![Page 24: World Wide Web has been created to share the text document across the world](https://reader036.vdocuments.mx/reader036/viewer/2022081604/56816380550346895dd4626a/html5/thumbnails/24.jpg)
Declaration Scriplet Expression
Enclosed in <%!..........%> <%........%> <%=………%>Contains One or more java
declarations or method definitions
Java code(condition checking,loops etc)
One java expression
What it does Creates a name possibly gives the name a value
Tells the system to do something
Has a value
When the JSP container runs it
When page is 1st visited or the JSP container reinitializes the page
Whenever someone visits the page
Whenever someone visits the page
![Page 25: World Wide Web has been created to share the text document across the world](https://reader036.vdocuments.mx/reader036/viewer/2022081604/56816380550346895dd4626a/html5/thumbnails/25.jpg)
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.
![Page 26: World Wide Web has been created to share the text document across the world](https://reader036.vdocuments.mx/reader036/viewer/2022081604/56816380550346895dd4626a/html5/thumbnails/26.jpg)
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”)%>
![Page 27: World Wide Web has been created to share the text document across the world](https://reader036.vdocuments.mx/reader036/viewer/2022081604/56816380550346895dd4626a/html5/thumbnails/27.jpg)
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()%>
![Page 28: World Wide Web has been created to share the text document across the world](https://reader036.vdocuments.mx/reader036/viewer/2022081604/56816380550346895dd4626a/html5/thumbnails/28.jpg)
5. getLocale()
(i) You are from <%=request.getLocale.getdisplayCountry()%>
(ii) You are using <%=request.getLocale.getDisplayLanguage()%> language.
![Page 29: World Wide Web has been created to share the text document across the world](https://reader036.vdocuments.mx/reader036/viewer/2022081604/56816380550346895dd4626a/html5/thumbnails/29.jpg)
Methods of remote object are:
1.sendRedirect()<%response.sendRedirect(http://abc.com/
index.html);>
2.sendError()<%response.sendError(404);%>
![Page 30: World Wide Web has been created to share the text document across the world](https://reader036.vdocuments.mx/reader036/viewer/2022081604/56816380550346895dd4626a/html5/thumbnails/30.jpg)
Forms and request parametersLogin.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>
![Page 31: World Wide Web has been created to share the text document across the world](https://reader036.vdocuments.mx/reader036/viewer/2022081604/56816380550346895dd4626a/html5/thumbnails/31.jpg)
Clicking the Submit button send the following request:
http://www.abc.com/authenticate.jsp?username=abc & password=xyz
![Page 32: World Wide Web has been created to share the text document across the world](https://reader036.vdocuments.mx/reader036/viewer/2022081604/56816380550346895dd4626a/html5/thumbnails/32.jpg)
authenticate.jsp<%If(request.getParameter(“pwd”).equals (“xyz”)){%><h2> Welcome <
%=request.getParameter(“username”)%></h2><%} else {%><% response.sendError(403);%><% } %>