JSP Presentation

18
Java Server Pages (JSP) An Overview Presented by: Rohit Singh Sengar

description

A 15 min presentation on JSP giving an overview and covering most of the JSP. Nice & excellent presentation suitable for introduction of JSP to any person.

Transcript of JSP Presentation

Page 1: JSP Presentation

Java Server Pages (JSP)

An Overview

Presented by: Rohit Singh Sengar

Page 2: JSP Presentation

2

Scope

Need of dynamic pages History of dynamic pages Servlets & its example JSP Overview JSP: Architecture & Life cycle JSP: Tags & Example JavaBeans Comparison of JSP with other server-side scripting

technologies. Pros and Cons of JSP References

Page 3: JSP Presentation

3

Need of Dynamic Websites

User Data: Web pages is based upon the user entered data.

Web pages is derived from data that changes frequently

Web pages interacts with databases 2 types of code is needed

1)Data representation2)Data generation

Page 4: JSP Presentation

4

History: Common Gateway Interface (CGI)

Earlier dynamic web pages were developed with Common Gateway Interface (CGI).

Web Applications eventually outgrew CGI because of the following:

Datasets became large Increased traffic on sites Trouble maintaining state and session information Performance bottlenecks Can involve proprietary APIs

Page 5: JSP Presentation

5

Servlets

It is regular Java code. There are new APIs, but no new syntax. It has unfamiliar import statements. The servlet and JSP APIs

are separate specification (and are also part of the Java 2 Platform, Enterprise Edition—J2EE).

It extends a standard class (HttpServlet). Servlets provide a rich infrastructure for dealing with HTTP.

It overrides the doGet method. Servlets have different methods to respond to different types of HTTP commands.

Servlet Life Cycle: It consist of followings The Init method The Service method The Destroy method

Page 6: JSP Presentation

6

Servlet Code: Example (for displaying Hello World)

import java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class HelloServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); String docType = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " + "Transitional//EN\">\n"; out.println(docType + "<HTML>\n" + "<HEAD><TITLE>Hello World</TITLE></HEAD>\n" + "<BODY BGCOLOR=\"#FDF5E6\">\n" + "<H1>Hello World</H1>\n" + "</BODY></HTML>"); }}

Page 7: JSP Presentation

7

JSP Overview

With a foundation in Java, JSP Threads incoming requests Supports custom tags. Interacts with a wide array of databases Serves dynamic content in a persistent and efficient manner

Initially the server automatically builds, compiles, and starts the servlet, from then on the servlets are stored in the web server’s memory in Java byte code

Extends the same portability, large class library, object-oriented code methodology, and robust security measures that have made Java a top choice

Does not require a Java programmer Better separation of Logic and presentation.

Page 8: JSP Presentation

8

Architecture

Page 9: JSP Presentation

9

JSP Life Cycle

Page 10: JSP Presentation

10

JSP - Tags

Tag Name Purpose1. Declaration tag <%! %> To declare variables & methods2. Expression tag <%= %> To embed any Java expressions & display any value3. Directive tag <%@ %> To set condition that applies to the whole JS Page.4. Scriptlet tag <% %> To write any valid block of Java code5. Action tag <jsp: > Enable the use of server side Javabeans, transfer control

between pages, browser independent support for applets6. Comment tag <%-- --%> Tell JSP engine to ignore the code

Page 11: JSP Presentation

11

JSP - Example

# Simple Java server page showing use of common tags.

# Java is very case

sensitive.

Page 12: JSP Presentation

12

JavaBeans

A JavaBean is a Java Class file that comes with specifications.

Defines how to create an Object, retrieve and set properties of the Object

It is used to minimize the java code in JSP. They are is used to communicate with Database & contain

various logic. Syntax: <jsp:useBean id=Bean name class=bean class

scope=page/request/session/application/> Syntax for setting value: <jsp:setProperty name=bean

name property=someProperty value=someValue/>

Page 13: JSP Presentation

13

Comparison of JSP

  PHP Cold Fusion ASP JSP

Cost Free $0 (Express version)-$5000 (Enterprise version)

Free with Windows NT, cost for 3rd-party software

Free

Language In Page PHP CFML VBScript, JScript Java

OS Platform Unix (Linux), Windows, MacOS, OS/2

Windows NT, Solaris, Linux

Windows 9x, NT, other platforms requires third-party ASP porting products

UNIX, Microsoft Windows, Mac OS, Linux

Supported Web server

iPlanet/Netscape Enterprise Server (NSAPI), MS Internet Information Server (IIS), Apache, Zeus, fhttpd, etc. (ver 4)

IIS, Netscape Enterprise Server , Apache, Website Server (WSAPI), CGI

IIS, Personal Web Server (PWS), other servers with third-party products

Any Web server, including Apache, Netscape and IIS 

Page 14: JSP Presentation

14

Comparison of JSP (Cont’d) …

  PHP ColdFusion ASP JSP

Supported Database

MySQL, mSQL, ODBC, Oracle, Informix, Sybase, etc.

ODBC, OLE DB, DB2, Oracle, Informix, Sybase, etc.

any ODBC-compliant database

any ODBC- and JDBC-compliant database

Portability Fair (DB portability) Good Fair Good

Scalability Fair Good Good Good

Component Support

COM, Java classes (version 4)

COM, CORBA, JavaBeans COM components

JavaBeans, Enterprise JavaBeans

Learning curve High (C, Perl) Low Medium (VBScript, JScript) High (Java)

Page 15: JSP Presentation

15

Pros and Cons Pros

Efficient Secure Convenient

Server engines typically have built-in infrastructures to handle parsing/decoding HTML form data, reading/setting HTTP headers, session tracking

Powerful Java behind the scene

Portable Write once, run anywhere

Inexpensive Various free or inexpensive engines

available

Cons Need for a Server Engine

Another engine to maintain Un-acceptably by the client

machine Virtual hosting of unrelated

sites on a single machine can cause problems (choose your server engine wisely)

High Learning Curve Steeper learning curve than

Cold Fusion

Page 16: JSP Presentation

16

JSP- A part of J2EE

Page 17: JSP Presentation

17

References

www.java.sun.com/products/jsp/ www.java.sun.com/developer/technicalArticles/Programming/jsp/ www.en.wikipedia.org/wiki/JavaServerPages www.visualbuilder.com/jsp/tutorial www.cetus-links.org/oo_javaserver_pages.html www.jspin.com www.courses.coreservlets.com www.onjava.com/topics/java/JSP_Servlets

Page 18: JSP Presentation

18

Thank You

Any Questions?