1 / 32

World Wide Web has been created to share the text document across the world.

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.

kolya
Download Presentation

World Wide Web has been created to share the text document across the world.

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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.

  2. 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

  3. 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.

  4. Disadvantages 1.Code is completely visible to the user and hence no security to data.

  5. 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

  6. 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.

  7. 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.

  8. 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.

  9. 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.

  10. 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.

  11. 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.

  12. 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

  13. Building blocks of JSP 1.JSP expressions 2.JSP scriplets 3.JSP declarations

  14. 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.

  15. <html> <head> <title>A Comment Test</title> </head> <body> <p> Today's date: <%= (new java.util.Date()).toLocaleString()%> </p> </body> </html>

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

  17. 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 --%>

  18. 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.

  19. We can also declare a method in a JSP declaration and can call it from a JSP expression. <%! int count=100; intplusone(int n) { return n+1; } %> The no: you are looking is<%=plusone(count)%> The no: is still <%=plusone(count)%>

  20. Scriplets • It is a piece of Java code sandwiched between the characters <% and %> • It takes the following form: <% java code %>

  21. <% if (Math.random(),0.5) { %> Have a <b> nice </b> day! <% } else { %> Have a <b>dull </b> day! <% }%>

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

  23. 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.

  24. Methods of request object are: • getHeader() • Browser your are using is <%=request.getHeader(“User-Agent”)%> • Cookie information stored is <%=request.getHeader(“Cookie”)%> • Your browser is willing to accept the following MIME types <%=request.getHeader(“Accept”)%>

  25. 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()%>

  26. 5. getLocale() • You are from <%=request.getLocale.getdisplayCountry()%> • You are using <%=request.getLocale.getDisplayLanguage()%> language.

  27. Methods of remote object are: 1.sendRedirect() <%response.sendRedirect(http://abc.com/index.html);> 2.sendError() <%response.sendError(404);%>

  28. 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>

  29. Clicking the Submit button send the following request: http://www.abc.com/authenticate.jsp?username=abc & password=xyz

  30. authenticate.jsp <% If(request.getParameter(“pwd”).equals (“xyz”)){ %> <h2> Welcome <%=request.getParameter(“username”)%></h2> <% } else { %> <% response.sendError(403);%> <% } %>

More Related