1 / 38

IA308 – Servlets and JSPs

IA308 – Servlets and JSPs. Christophe Coenraets Manager, Technical Evangelists Internet Applications Division ccoenrae@sybase.com. Servlets Topics. Dynamic Web Sites Architectures Servlets Benefits Servlet's Life Cycle Building a Servlet Tracking Sessions. Site Map. ListDest.jsp.

hollye
Download Presentation

IA308 – Servlets and JSPs

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. IA308 – Servlets and JSPs Christophe Coenraets Manager, Technical Evangelists Internet Applications Division ccoenrae@sybase.com

  2. Servlets Topics • Dynamic Web Sites Architectures • Servlets Benefits • Servlet's Life Cycle • Building a Servlet • Tracking Sessions

  3. Site Map ListDest.jsp Destination.jsp TripFinder.jsp LogonServlet Logon.htm Payment.jsp LogonError.htm Booking.jsp Customer.jsp

  4. <HTML> Aruba Bermuda Bahamas </HTML> Static Web Site http://www.myvacation.com/ListDest.htm HTTP Server HTTP HTML

  5. <HTML> Aruba Bermuda Bahamas </HTML> Dynamic Page Generation Using CGI http://www.myvacation.com/cgi/ListDest.exe HTTP Server CGI Application ODBC / Native HTTP HTML

  6. <HTML> Aruba Bermuda Bahamas </HTML> Dynamic Page GenerationUsing Servlets http://www.myvacation.com/servlet/ListDest HTTP Server Servlet Container JDBC HTTP HTML

  7. What is a Servlet? • Server side Java program that extends the functionality of a Web Server • Used to dynamically generate HTML documents • Comparable to: • CGI • Netscape NSAPI • Microsoft ISAPI • Apache Modules

  8. Written in pure Java Platform independent Can take advantage of JDBC, EJB, JMS, JavaMail, JavaIDL, RMI, ... Server independent Scalability Don’t start new process for each request Can run in same server process as HTTP server Multi-threaded Servlets Benefits

  9. Building a ServletUsing the Servlet API • Extend HttpServlet • Code Servlet's life cycle Methods Servlet GenericServlet HttpServlet LogonServlet

  10. Thread doGet( ) Thread Servlet Thread Servlet Life Cycle Servlets Container HTTP Server init( )

  11. Thread Thread Servlet Life Cycle Servlets Container HTTP Server init( ) doGet( ) Servlet

  12. Thread Servlet Life Cycle Servlets Container HTTP Server init( ) doGet( ) Servlet

  13. Servlet Life Cycle Servlets Container HTTP Server init( ) doGet( ) destroy( ) Servlet

  14. Servlet Life Cycle Servlets Container HTTP Server

  15. Advanced Servlet Support in PowerJ 3.6 • Java Servlet 2.2 wizard • Generates Servlet class • Deployment descriptors • Web Archive (WAR) target (optional) • Design time visual class for drag-and-drop programming • Automated deployment • Remote debugging

  16. Advanced Servlet Support in EA Server 3.6 • Access to connection caches • Configurable threading model • Access to external parameters • Inter-server component invocations • Refresh • Remote debugging • Logging support

  17. Building the Logon ServletDemo ListDest.jsp LogonServlet Logon.htm LogonError.htm

  18. Servlets as Part of J2EE • Contribution • Provides platform/server independent and scalable architecture for developing HTTP-based applications • Limitations • Modification of static content requires recompilation • Business logic not reusableby non Web clients Addressed by JSP Addressed by EJB

  19. Java Server PagesTopics • JSP Architecture • Anatomy of a JSP • Directives • Scripting Elements • Standard Action Tags

  20. Site Map ListDest.jsp Destination.jsp TripFinder.jsp LogonServlet Logon.htm Payment.jsp LogonError.htm Booking.jsp Customer.jsp

  21. <HTML> Aruba Bermuda Bahamas </HTML> Dynamic Page GenerationUsing Servlets http://www.myvacation.com/servlet/ListDest HTTP Server Servlet Container JDBC HTTP HTML EA Server

  22. <HTML> Aruba Bermuda Bahamas </HTML> Dynamic Page GenerationUsing Java Server Pages (JSP) http://www.myvacation.com/ListDest.jsp HTTP Server JSPEngine JDBC HTTP HTML Servlet Container EA Server

  23. Java Server Pages • Web scripting technology • Creation of dynamic content using static templates • Combine markup (HTML or XML) with Java Code to produce a dynamic Web Page • Similar to Microsoft ASP and PowerDynamo • Uses Java as its scripting language • Full power of the Java language • Simple tags allow non Java developer to generate dynamic content

  24. A Simple JSP <html> <body> <%@ page language="java" import="" %> <H1>Welcome back, <% String user = (String) session.getAttribute("user"); out.println(user); %> </H1> </body> </html>

  25. Java Server Pages and Servlets • Servlets • HTML enclosed in Java code • JSP • Java code enclosed in HTML • Easier to Author • Better tool support

  26. How it Works User Request Server FileChanged ? Create Source Compile Execute Servlet

  27. Web Application Development Roles • JSP technology promotes application partitioning and separation of tasks • Java developer builds components encapsulating the application logic • Page designer assembles the application with a few method calls

  28. Anatomy of a JSP • Static template text • Dynamic content • Directives • Scripting elements • Standard actions • Custom tags

  29. Directives • Gives page information to JSP engine • Page directive <%@ page language="java" import="java.sql.*" errorPage="ErrorPage.jsp" %> • Include directive <%@ include file="header.htm" %>

  30. Creating ListDest.jspDemo

  31. Scripting Elements • Declarations (variables and methods) <%! String destination; %> • Scriptlets <% destination = request.getParameter("destination");%> • Expressions <p>Destination: <%= destination %>

  32. Standard Action Tags • <jsp:forward> • Forwards request to HTML page, JSP, or servlet • <jsp:forward page="relativeUrl" /> • <jsp:include> • Includes data in a JSP page from another file • <jsp:include page="relativeUrl" flush="true" /> • <jsp:plugin> • Downloads Java plugin to browser to execute applet or bean

  33. Standard Action TagsUsing JavaBeans Component • Locates or instantiates a Bean with a specific name and scope <jsp:useBean id="cd" class="samples.Cd" /> • Sets a property value or values in a Bean <jsp:setProperty NAME="cd" PROPERTY="artist" VALUE="Sting" /> • Gets the value of a Bean property artist=<jsp:getProperty NAME="cd" PROPERTY="artist" />

  34. Using Custom Tags • Taglib directive • Defines a custom tag library • Provides a way to extend JSP's native functionality without breaking compatibility • Syntax <%@ taglib uri="URIToTagLibrary" prefix="tagPrefix" %>

  35. Creating Destination.jspDemo

  36. JSP Advanced Support in PowerJ 3.6 • HTML and JSP editor with syntax highlighting • Design time syntax checking • Automated deployment (WAR file) • Remote debugging

  37. JSP Advanced Support in EA Server 3.6 • Remote debugging • Access to connection caches • Configurable threading model • Access to external parameters • Inter-server component invocations • Refresh • Logging support

  38. Summary

More Related