Introduction to Java Server Pages technology by Naomi Chen - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

Introduction to Java Server Pages technology by Naomi Chen

Description:

Jscript or VBScript. Java. Base Language. Microsoft only ... standard HTML tags & scripts (JavaScript/VBscript) new tags for scripting in the Java language. ... – PowerPoint PPT presentation

Number of Views:62
Avg rating:3.0/5.0
Slides: 23
Provided by: naomir4
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Java Server Pages technology by Naomi Chen


1
Introduction to Java Server Pages technologyby
Naomi Chen
2
What is JSP?
  • Java based technology that simplifies the
    developing of dynamic web sites
  • JSP pages are HTML pages with embedded code that
    allows to access data from Java code running on
    the server
  • JSP provides separation of HTML presentation
    logic from the application logic.

3
JSP Flow
4
Comparison with existing technologies CGI
  • CGI(Common Gateway Interface) programs (typically
    written in C or Perl) interact with the user by
    reading the user's input, HTML forms, and
    returning custom HTML pages.
  • Problems
  • For each user request the CGI script must be
    loaded, run, and unloaded.
  • Designed to handle only a single request needed
    additional session support (to remember a users
    state between requests for a example).
  • JSP vs. CGI
  • JSP can maintain state on the server between
    requests
  • Spawns a new thread for each request
  • Does not have to be loaded each time, once it has
    been initialized
  • Runs in a ready-loaded JVM as an extension to the
    web server.

5
Comparison with existing technologies ASP
  • ASP (Active Server Pages) from Microsoft is the
    main competing technology for JSP.
  • JSP ASP are similar in the way they support the
    creation of dynamic web pages, using HTML
    templates, scripting code and components for
    business logic.

6
Comparison with existing technologies ASP
(continue)
  • ASP used on Microsoft IIS pr PWS web servers. Two
    third parties, Chili!Soft and Halcyonsoft sell
    software that allows ASPs to be uses with other
    platforms the main problem is in porting the COM
    components to the new platform.
  • JSPs score over ASP
  • JSPs are interprted only once, to Java byte-code,
    and re-interpreted only when the file is modified
  • JSPs run on all the main web servers
  • JSPs provide better facilities for separation of
    page code and template data by means of
    JavaBeans, Enterprise JavaBeans and custom tag
    libraries.
  • For more information see Sun JSP vs. ASP page

7
Comparison with existing technologies Servlets
  • Servlets are standard, server-side Java
    applications that extend the capabilities of a
    Web server.
  • Java Servlets programming model is similar to CGI
    scripts.
  • Servlets run inside a single process associated
    with a web server.
  • Instead of creating a process for each request
    (as CGI) JVM cerates a Java thread to handle each
    servlet request.
  • JVM persists beyond the life of a single request
    (so requests can share data and resources).
  • Essence Java code that outputs the HTML
    (out.println approach).
  • All benefits of the core Java platform OOP
    model, cross-platform, memory management, rich
    collections of Java APIs., etc.
  • Problems
  • All document contents, both static and dynamic,
    reside in program source code.

8
JSP Technology
  • JSP technology provides a way to combine the
    worlds of HTML and Java servlet programming.
  • JSP specs are built on the Java Servlet API.
  • JSP supports two different styles for adding
    dynamic content to web pages
  • JSP pages can embed actual programming code
    (typically Java)
  • JSP supports a set of HTML-like tags that
    interact with Java objects on the server (without
    the need for raw Java code to appear in the
    page).

9
JSP Example Hello World
  • 1.
  • 2.

10
SimpleJSP.jsp
11
SimpleJSP.jsp - the Bean edition
  • JSP includes tags for interacting with JavaBeans.
  • JavaBean is a simply Java class that follow
    JavaBeans specs rules for defining a Beans ctor
    methods for accessing and setting their
    properties.

12
SimpleJSP.jsp - the Bean edition
13
JSP Example Hello World
  • In both cases the http request is
  • http//localhost8080/SimpleJSP.jsp?nameNaomi
  • The response from JSP container would be

14
How it is work?
  • Client request for a page ending with ".jsp.
  • Web Server fires up the JSP engine.
  • The JSP engine checks to see if the JSP file is
    new or changed.
  • The JSP engine takes the page and converts it
    into a Java servlet (by JSP parser)
  • The JSP engine compiles the servlet (by standard
    Java compiler).
  • Servlet Engine executes the new Java servlet
    using the standard API.
  • Servlets output is transferred by Web Server as
    a http response.

15
JSP Pages content
  • standard HTML tags scripts (JavaScript/VBscript)
  • new tags for scripting in the Java language.
  • Expressions
  • ltexpression gt or XML variant
  • ltjsp expressiongtexpression lt/jspexpressiongt
  • For Example
  • lt fact(12) gt
  • lt (hours lt12) ? AM PM gt
  • lt Math.pow(radius, 2) gt
  • Scriptlets
  • lt scriptlet gt or XML variant
  • ltjspscriptletgt scriptlet lt/jspscriptletgt
  • Declarations
  • lt! declaration (s) gt or XML variant
  • ltjspdeclarationgt declaration(s) lt/jsp
    declarationgt
  • For Example

16
JSP Pages content cont.
  • JSP directives is a set of tags for providing
    the JSP container with page specific instructions
    for how the document should be processed.
    Directives affect global properties of the JSP
    page.
  • lt_at_ page attr1val1 attr2 gt
  • Comments for adding documentation
  • Comments that will be in the output
  • lt!-- comment --gt
  • JSP comments
  • lt-- comment --gt
  • Scripting language comments
  • lt / comment / gt

17
JSP Pages content cont.
  • Actions and implicit objects
  • JSP implicit objects
  • page out
  • config session
  • request application
  • response pageContext
  • exception

18
JSP Pages content cont.
  • Beans tags
  • allows JSP pages to call reusable components
    called JavaBeans components.
  • The tag ltjspuseBeangt syntax is
  • ltjspuseBean id"Bean_name"
    scope"scope_value" class"class_name"
    beanName"ser_filename" type"class_or_interface_n
    ame" gt properties tags lt/jspuseBeangt
  • ltjspsetPropertygt tag syntax is
  • ltjspsetProperty name"property_name"
    property"property_value" /gt

19
JSP benefits
  • Java-based technology
  • Vendor-neutral
  • Full access to underlying Java platform
  • Performance
  • Reusable components (JavaBeans)
  • Separating presentation and implementation

20
Resources
  • Sun JSP 1.1 Specs and description
  • Server Side Java Resource Site
  • IBM education courses
  • JSP resource index
  • JSP insider

21
The end
22
Scriptlet Example
Write a Comment
User Comments (0)
About PowerShow.com