84
ITL Infosys (E&R) ITL Infosys (E&R) Server side Programming (Application framework for E-business) Radhika Santhanakrishnan

servletpresentation[1]

Embed Size (px)

Citation preview

Page 1: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Server side Programming

(Application framework for E-business)

Radhika Santhanakrishnan

Page 2: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

E-Business

• Organization connecting critical business systems directly to key constituencies(customers, employees, suppliers,distributors) via the web(Internet,Intranet, Extranet)

• Hence, E-Business transforms key business process.

Page 3: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Introduction• E-Commerce Java-based programming

model framework with basic elements of the framework that support any Web applications

• Primary focus is on the server-side of Web applications( Internet applications)

• 3-tier Architecture(Application Server(+web server), client, Database Server)( Why?)

Page 4: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Http request contains the application name and URL

Http request contains the client info & the data filled by the user in the form.

Web application server leverages the request to the particular application or database or external application

The application then sends a response in the form of HTML to the client

Page 5: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Web Interaction Model

Page 6: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Page 7: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Why do we need a framework?

• Maximize ease and speed of development & deployment

• Accommodate any client device• Ensure portability across a diverse

server environment• Leverage and extend existing

assets

Page 8: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

UI Models

• Client Driven UI Model• Server Driven UI Model

Page 9: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Page 10: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Server Driven UI Style

it leverages standard Web protocols like HTTP or its secure form HTTPS, and standard data streams like HTML and MIME,

the client consists of a Web browser interpreting HTML (possibly including scripting and Java applets),

the server side of the application is hosted in a Web server/application server and consists of

a collection of application fragments that

implement the bulk of the business logic.

Page 11: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Advantages

• Universal access• any device that supports HTML

• Reduced cost of application management:

• management content or change management is only on the server side

• Ideal for Internet web applications

• Leverage existing applications

Page 12: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Challenges

Mastering a number of strong daunting standards, such as TCP/IP, HTTP, HTTPS, HTML, MIME, SMTP, IIOP, and others.

Lower level of interactivity (since user interactions require communication with a server)

The basic Web interaction model is sessionless(Each request contains only its request content). Hence, The application programmer must use information encoded in HTTP requests and resources shared across the series of interactions to establish the continuity of the application

communicating with the existing assets which typically require specialized protocols and data streams.

Page 13: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Application Building Blocks

• Servlets

• Execution Context

• Connectors

• Dynamic Server Pages

• Web Application Infrastructure

Page 14: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Servlets• Servlets are the units of Java programs that handle Web

requests and extends from HttpServlet class

• The Servlet class is instantiated on the first request

• Each servlet class must implement a service method which is called once for each Web request and is passed two parameters, a request and a response

• Requires only (Execution layer)(JRE +servlet API) on any web server

• Better alternative to CGI, PERL, (SSS)ASP, SSI, API-SSPlugin(NSAPI, ISAPI), Comprehensive server Programming -Lotus Domino(Vendor Specific)( IBM servlet Express)

Page 15: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Role of Servlet

• Provides coordination between program and content

• the service method of a servlet is expected to extract information from its request parameter, perform a computation, and then send back an HTML (or other MIME type) response to the client ( can be doget()/dopost(), types of http requests)

• Each servlet is for a specific request

• Stores any serializable object into session object

• Implements simple business logic

• Connects to RDB, can call n- command beans (basic logic for a request),

• Servlet Bean- ( activated from a serialized preconfigured bean), ( customizable for different pages /applications etc )

Page 16: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Servlet design

• The Web server will create an instance of the appropriate servlet class for the first request to a particular URI (URL+URN) and then reuses this instance for each subsequent request to the same servlet

• If the servlet is a JavaBean, then each instance will be created using the JavaBean activation model which allows the servlet to be activated from a serialized, preconfigured bean

• Servlets must be designed to be multi-user and multi-thread ready since, in most cases, one instance of the servlet class is created by the Web server and all requests for the servlet are routed to that single instance in a multi-threaded manner

Page 17: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Execution Context

• HTTP sessionless and stateless, each request carries only its request context. Hence we need to maintain the context

• The context generally maintained are – Object context– Request Context– Session context– User profile context– object context

• Maintaining Session:One of the challenges of servlet design is to provide continuity of application execution given the sessionless nature of Web interactions

Page 18: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Request Context• The request context is provided in the request and response

parameters that are passed to the servlet's service method. The request context provides very complete access to the content of the HTTP request, including:

– all the URL information,

– all request parameters,

– the remote user's id and password, if known,

– the type of authentication used for the remote user, and

– information about the brand and version of the remote Web browser software.

• The request context also provides access to the session context and the facilities for responding to the request, such as the java.io.PrintWriter object for sending MIME data back to the

remote client.

Page 19: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Session Context• The session context is an object, that allows servlets to save and

retrieve information about the interaction with a particular user over a series of HTTP requests

• The servlet can store any serializable object into the session object which it can then access on subsequent requests that are part of the same session

• Session objects are supported in a Web server cluster environment

• Session objects last until

– an application specified time occurs between requests from a particular user

– or the session ends (Web server or communications failure)

– or they can be specified to last indefinitely until explicitly destroyed by application logic (not persistent)

Page 20: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Object Context• servlet instances are usually created on the first request

& reside in memory

• Object Context can be used for caching information, such as database connections or external data

Page 21: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

User Profile Context

• Persistant store( UPO spans across sessions/applns)

• provides a partial, predefined schema for user information that can be extended by the application developer

• the user profile information can be saved in the database/file.

• Stores information about a user such as: name, street address, e-mail address, phone number, buying preferences, etc

Page 22: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Connectors

• Java libraries and supporting tools that support access from the Framework's programming environment to various external data and application servers including CICS, Encina, IMS, DB2, Component Broker, Domino, and MQ.

• Connectors provide Java programmers high quality access to these facilities without requiring the programmer to write C or other non-Java code.

• Shields the programmer from the usually proprietary network protocols needed to access these servers

• support for connection pools and appropriate pool management

Page 23: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Dynamic Server Pages

• Dynamic Server Pages are HTML pages extended with a number of mechanisms to allow dynamic content to be added to the page as it is sent to the client.

• All processing of DSP HTML extensions is done on the server and each of the extensions is either removed or replaced before the page is sent to the client. No additional client support is required

• DSP supports the following extensions

• Server Side Includes (SSIs), Java SSI, JSP,

Page 24: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

SSI

– <!--# include file = “filename” -->

– includes fragment to be included or shared by a number of response pages

– single point of update

– eg: prologs/epilogs, legal discliamers, copyrights etc

• Java SSI

– HTML tags that allow servlets to be executed

– difference is that this servlet returns only a part of the HTML(dynamic part) rather than the whole HTML

– <Servlet name = com.inf.myebusiness.Advertising>

<param name = user type value = “paging” >

</servlet>

Page 25: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Java Server Pages (JSP)

• Adds SSS logic to HTML page• fine grained control, complete

application development• translated to servlets on execution• provides HTML tags to inline java code• jsp tags also include java script,

BASIC, REXX( but translated to servlets)

Page 26: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Web Application Infrastructure

• Runtime Services– Directory Support ( JNDI directory services

scalable sharable and secure )– Certificate Server-produces security

certificates authenticates users/applns– Servlet Access Control - user /group based

for servlets & DSP– Servlet Chaining(priority execution) and

Filtering– RDB Access( JDBC & connection caching)

Page 27: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Summary so far

• The application framework for e-business programming model includes all necessary elements to write the server side of the web application, including

– servlets ( for program elements)– Execution context to provide program

elements with application context– connectors to connect to external world– dynamic pages to separate program logic

from user interface– needed web application infrastructure

Page 28: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Roles and development models

• Content developers• business logic • project coordinator /producer• graphic designer• web page composer

Page 29: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Components of a structured Interaction

• Servlets• DSP• Formatting Beans• Command Beans• Business Logic

Page 30: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Page 31: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Page 32: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Java Services

• Servlet and JSP support

• Enterprise JavaBean (EJB)

• Database access services

• Directory access, the Java Naming and Directory Interface (JNDI)

• Security services, Java SSL (JSSL), Java Cryptography Extensions (JCE), and Java Authentication Services (JAS) Mail access and creation, the JavaMail API Java Transaction API (JTA) Java Messaging Services (JMS)

Page 33: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Framework database services

• Manage both traditional data (record-structured alphanumeric data) and nontraditional data (such as text, multimedia, spatial, etc.) along with user defined data types for specialized

business requirements. Combine the ability to define complex data types and

associated functions with relational database features such as multiple views, structured query and fine-grained update

concurrency Support development and execution of database application

programs, stored procedures and user defined functions using the Java and JavaBeans programming model

provide query and update access to database information using SQL, SQL-J, and JDBC interfaces; this includes Web applications updating the database using two-phase commit

Page 34: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Collaboration Services

• coordination of business workflow processes.

• integrate information from any resource, manage what is shown to users, confer a measure of interactivity between information and the user, and manage the content through a business process in which employees, customers, and business partners can participate.

• accelerate the flow of information through an organization's decision making and approval processes.

• connecting existing structured business data and transaction systems with people to create new business processes and workflows.

Page 35: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Development Tool Support

• WebSphere Application Server• VisualAge for Java• NetObjects Fusion and Script Builder• BEA WebLogic Tengah Application

Server• Netscape Application Server• Domino Application Server….

Page 36: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Web Applications

Page 37: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Web Client

• Usually Browsers • client technologies, such as HTML,

DHTML, Java applets, and JavaScript

• XML

Page 38: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Client Driven

• The Client Driven UI model has the following advantages: – familiar model to a traditional client/server background.

– look more like standard windowed applications.

– UI rendering is distributed to each client, reducing the computational load on the Web server

• The Client Driven UI model has some disadvantages: – The client code (applets or JavaScripts) tends to be large

and requires more time to download

– display updates can occur with as few remote method calls as possible

– remote method call protocol delay the start of a application to an unacceptable period of time.

Page 39: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Conclusions• simplifies application development and

deployment

• supports heterogeneous client and server platforms

• leverages existing skills and assets

• delivers a secure, scalable, reliable, and manageable environment

• and provides the freedom to implement using many vendor's products

Page 40: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Developing E-business Applications using Servlets

and JSP

by Radhika Santhanakrishnan

Page 41: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

E-Business

• Organization connecting critical business systems directly to key constituencies(customers, employees, suppliers,distributors) via the web(Internet,Intranet, Extranet)

• Hence, E-Business transforms key business process.

Page 42: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Objectives

• Java server side development ( A quick recap)

• What are Java Servlets?

• Enhancing web server functionality with safe, efficient, portable and powerful servlets

• Servlet container and servlet API

• Life cycle of a servlet

• Servlet error handling

• list servlet servers

Page 43: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Java for server side-1

• WWW service• web application & Head, Get and

Post• Alternate server programs

Page 44: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Java for server side-2

• Platform independence• efficiency• Access to enterprise Java API• Reusability• Modularity• Object-OrientedUse JSDK - The first step to realize the power of Java platform

Page 45: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Java Servlets

• Java Servlets are– platform independent– efficient– 100% Object-Oriented– They offer developers a way in which

to extend the benefits of the Java platform to the web server

Page 46: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Introduction

• Servlet API is a class with a basic defn of a server

• add functionality to a web server • support a request/response computing

model • Java Servlet Development Kit (JSDK),

you use the Java Servlet API to create servlets for responding to requests from clients

Page 47: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Services provided by a servlet

A servlet is a Java component that can be plugged into a Java-enabled web server to provide custom services. These services can include:

New features

Runtime changes to content

Runtime changes to presentation

New standard protocols (such as FTP)

New custom protocols

Page 48: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Basic Servlet flow

client

browser

servlet

Web server

Response HTTP

Request HTTP

Response

invokes

Page 50: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Servlet Container

– Handles client requests– passes a request to a servlet– returns request to a client

Servlet container(pure Java web server)

Servlet API

Interface between Servlets and containers

Defines what the container will call

Guarantees init is called before service method

Classes of objects which the container will pass to the servlet

Page 51: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Web Servlet Interface

• The web server is responsible for initializing, invoking, and destroying each servlet instance using a servlet container

• A servlet container communicates with a servlet through a simple interface, javax.servlet.Servlet. which consists of three main methods: init(),service()& destroy()

• and two ancillary methods: getServletConfig() getServletInfo()

Page 52: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Loading a servlet

• Ideally the servlet can be loaded into memory when either of the following situations occurs– 1. When the web server is started– 2. At the first request– 3. When the administrator of the web

server explicitly loads the servlet

Page 53: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Servlet Life Cycle - 1

• The servlet container creates an instance of the servlet

• the containetr call sthe instances init() method

• If a container has a request for the servlet , it calls the instance’s service method.

Page 54: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Servlet Life Cycle - 2

• Before destroying the instance, the container calls its destroy method

• The instance is destroyed & marked for garbage collection

Page 55: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Managing a billion requests

• Thread pooling by servlet container

Page 56: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Third Party Full Server Implementations

• Acme Acme.Serve• Apache Web Server• ATG Dynamo Application Ser

ver IBM Internet Connection Server IBM VisualAge WebRunner Toolkit

• iPlanet Web Server• iPlanet Application Server• jo!• KonaSoft Enterprise Server

LiteWebServer• Live Softeware Jrun• Lotus Domino Go Webserver

• Mort Bay Jetty• Netscape Application Server

Novocode NetForge• Paralogic WebCore

ServletFactory• Tandem iTP WebServer

vqServer• W3C Jigsaw• WebEasy WEASEL• WebLogic Tengah

Application Server• Zeus Web Server

Page 57: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Server Add-On Engines

Gefion Software WAICoolRunner

IBM WebSphere Application Server

Live Software JRun

New Atlanta Communications ServletExec

Unicom Servlet CGI Development Kit

Page 58: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Creating a Servlet - 1

• 1. Write the servlet – a. Import the necessary Java packages

– Inherit from GenericServlet or the HTTP convenience class HttpServlet

– b. Override the service method this is where the actual work is done by the servlet)

– c. Save the file with a .java filename extension

Page 59: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Creating a Servlet - 2• 2. Compile the servlet

– a. Make sure servlet.jar is included in your classpath

– Invoke javac

• 3. Install the servlet – a. Use the Web/application Server's Administration Tool

to install it, and

– optionally configure it

• 4. Test the servlet – b. Invoke the servlet from a JDK1.1-compatible browser.

Page 60: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Creating a Servlet - 3 import java.io.*; import javax.servlet.*;

import javax.servlet.http.*;

/* Create a class which inherits from GenericServlet or HttpServlet.*/

public class MyFirst extends HttpServlet

{

/** Override the service method.

* Here we handle the HTTP GET method by

* building a simple web page. */

Page 61: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Creating a Servlet - 4 public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException

{ PrintWriter out; String title = "MyFirst Servlet Output";

/* set content type and other response header fields first */

response.setContentType("text/html"); // then write the data of the response out = response.getWriter(); out.println("<HTML><HEAD><TITLE>"); out.println(title);

Page 62: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Creating a Servlet - 5

out.println("</TITLE></HEAD><BODY>"); out.println("<H1>" + title + "</H1>"); out.println("<P>This is output from”+ “ MyFirst servlet."); out.println("</BODY></HTML>"); out.close(); } }

Page 63: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Creating a Servlet - 6• Compile the servlet

– javac -cp server_root/lib/servlet.jar -d server_root/servlets MyFirst.java

– where server_root is the directory of the installed Java Web Server.

• Deploy the servlet – usually copy the servlet .class file to a servlet

folder or classes folder of the web/application server

• Test the servlet– http://host_name:port/servlet/servlet_name

– For example: http://ecommerce:8080/servlet/FirstServlet

Page 64: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Servlet

• Requests can come in the form of an

HTTP,URL,FTP,or a custom protocol

• Single threaded servlets

• Temporary vs Permanent Servlets

• servlet security

Page 65: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Servlets available to us

• BookStoreServlet - The BookStore servlet returns the main web page for Duke's Bookstore

• BookDetailServlet - The BookDetail servlet returns information about any book that is available from the bookstore

• CashierServlet - The Cashier servlet takes the user's name and credit-card number so that the user can buy the books

• CatalogServlet - The Catalog servlet adds books to the user's shopping cart and prints the catalog

• ReceiptServlet - The Receipt servlet clears the shopping cart, thanks the user for the order, and resets the page to the BookStore's main page

• ShowCartServlet - The ShowCart servlet returns information about the books that the user is in the process of ordering

Page 66: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Supporting Servlets Available

• BookStoreDB - Sets up the database with the appropriate things for our bookstore

• BookDBFrontEnd - Object that gets information from the Duke's Bookstore database

• BookDetails• Cashier• ShoppingCartItem

Page 67: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Objectives

• Appreciate the need for JSP• Discuss the Java server page

architecture• Encapsulate logic in a JavaBean

component and integrate it with JSP• Walk thru a detailed example using

JSP, showing typical web application architecture

Page 68: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

JSP Key features

• Simplified page generation• Integration with the Java platform• Platform- and server-independence• Provides all advantages of Java

servlets and Java platform

Page 69: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Architectural Overview

• A JavaServer page is a simple text file consisting of HTML or XML content along with JSP elements( Java code)

• A JSP is compiled to a servlet for execution

Page 70: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

JSP Servlet Source file

• View the servlet source file• javax.servlet.jsp package

• classes– JSPPage– HTTPJspPage

• interface for the compiled JSP– jspInit()– jspDestroy()– _jspService(HttpServletRequest request,

HttpServletResponse response)

Created by JSP author

Created by JSP Engine

Page 71: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Elements of a JSP• DirectivesDirectives-global information to the

page• DeclarativesDeclaratives-page wide variable and

method declaration• ScripletsScriplets- the java code embedded in a

page• ExpressionsExpressions- formats the expression as

a string for inclusion in the output of the page

Page 72: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

JSP

• Portability Apart from all advantages of servlets, allows separation of content generation (logic) from content presentation and they leverage reusable components (such as JavaBeans components

• Composition JavaServer Pages architecture can include reusable Java components. The architecture also allows for the embedding of a scripting language directly into the JavaServer Pages file.

• Processing (.html with JSP tags, with associated components in the form of .class, .jar, or .ser files

• Access Models

Page 73: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Access Model 1

Page 74: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Access Model 2

Page 75: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Deciding on the access models

• JSP as the front-end to a servlet If a GUI is necessary to collect the request data--use a JavaServer Pages file.

JSP as the back-end to a servlet If the request and request parameters are otherwise available to the servlet, but the results of the servlet processing requires a graphical interface to present them--use a JavaServer Pages file.

only the servlet If presentation layout is minimal (will not require very many println lines in your servlet code) and you don't need to make that presentation logic available to a customer or your webpage designer, then a Servlet might suffice.

Page 76: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Creating a JSP - 1• Write the JSP file.

– Declare any JavaBeans components.

– Use tag-centric syntax to access Bean properties or scripting-centric syntax to provide desired functionality.

– Save the file with a .jsp filename extension.

• Place the JSP file and any associated files. – Place the .jsp files under your doc root directory (/public_html

by default).

– Place associated .class, .jar, or .ser files in a directory on your CLASSPATH (/classes by default).

• Test the JSP file. Invoke the JSP file from a web browser.

Page 77: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Creating a JSP - 2

• Only HTML<html><head><title>HTML-only JSP File</title></head><body><h1>Hello World (HTML)</h1></body></html>

Page 78: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Creating a JSP - 3• HTML and component-centric tags

<html><head><title>HTML plus Bean JSP File</title></head><jsp:useBean id="clock" scope="page" class="sunexamples.beans.JspCalendar" /><body><h1>Hello World (HTML)</h1><p>Today is: <jsp:getProperty name="clock" property="date"/></p></body></html>

Page 79: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

JSP and layers

Page 80: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

How does JSP work?• JSP technology-based pages use XML tags and

scriptlets• separates the page logic from its design and display• uses Java programming language-based scripting

language and JSP technology-based pages are compiled into servlets and remains in memory

• JSP technology-based pages may call beans or Enterprise Beans to perform processing on the server

• implemented using a translation phase that is performed once, the first time the page is called. Since thet remain in memory as servlet instances subsequent calls to the page have very fast response times

Page 81: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

XML and JSP

• JSP specification supports XML implementations

• XML tags may be included as static template portions of the JSP

• Dynamic generation of XML tags occurs through bean components or custom tags that generate XML output.

• You can create and manipulate JSP technology-enabled pages using XML tools ( JSP 1.1)

Page 82: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Is it Y2k Compatible• Bug is that dates between March 1, 2000 and

December 31, 2000 are interpreted to be 1 day previous to the date sent by the client. For example, if a client set a date header for March 10th, the server would interpret the date as March 9th

• jsdk.jar y2k patch will be part JSDK and will be fully Year 2000 compliant

• The Java Servlet Development Kit 2.1 is fully Year 2000 compliant.

• The Java Servlet Development Kit 2.0 requires a patch for full Year 2000 compliance

Page 83: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Conclusions• simplifies application development and

deployment

• supports heterogeneous client and server platforms

• leverages existing skills and assets

• delivers a secure, scalable, reliable, and manageable environment

• and provides the freedom to implement using many vendor's products

Page 84: servletpresentation[1]

ITL Infosys (E&R)ITL Infosys (E&R)

Further Reading

• Information on JSP http://java.sun.com/products/jsp/.

• http://java.sun.com/products/jsp/techinfo.html

• Information on Servlet

• http://java.sun.com/products/servlet