Java Server Pages JSP - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Java Server Pages JSP

Description:

A scriptlet is a piece of Java code sandwiched between % and % A scriptlet can make use of any java API as long as it is appropriate for the web purpose. ... – PowerPoint PPT presentation

Number of Views:320
Avg rating:3.0/5.0
Slides: 13
Provided by: aalg
Category:
Tags: jsp | java | pages | server

less

Transcript and Presenter's Notes

Title: Java Server Pages JSP


1
Java Server PagesJSP
  • By
  • Abdulmalik S. Al-Gahmi

2
Outline
  • Introduction
  • How JSP works
  • JSP Scripting Elements
  • Implicit Objects
  • JSP Directives
  • An Example United Way project

3
Introduction
  • Putting Java code along with HTML code.
  • Server-side of the web
  • JSP, ASP, PHP, SSI, and JavaScript
  • JSP Building elements
  • Scripting elements
  • Directives
  • Actions
  • XML Tags

4
How does JSP work?
5
Scripting Elements(1)
  • Comment Element Used to clarify the logic of the
    JSP code.
  • Example
  • --
  • Out.print(new java.util.Date())

6
Scripting Elements(2)
  • Declaration Element
  • It has the form
  • It is used to declare class members variables or
    methods. It does not have any other code than
    declaratives.
  • Class members created here will last forever as
    long as the class object is alive.
  • Example
  • int x 0
  • int square(int x)
  • return x x

7
Scripting Elements(3)
  • Expression Element
  • It has the format
  • An expression in this context is not a complete
    java statement it is just a part of it.
  • Example
  • The square of is as
    calculated by a JSP program.

8
Scripting Elements(4)
  • Scriptlets
  • A scriptlet is a piece of Java code sandwiched
    between
  • A scriptlet can make use of any java API as long
    as it is appropriate for the web purpose.
  • Variables defined in a scriptlet are local.
  • Example
  • for(int i1 i
  • out.print(hello world!
    )

9
Mapping a JSP Document to a Java Class
  • JSP Document
  • test
  • Java Class
  • class doc-name-1 ...
  • //declaration 1 here
  • //Declaration 2 here
  • public void _jspService()...
  • //Scriptlet 1 here
  • //Scriptlet 2 here
  • // Expression here
  • ...
  • ...

10
Implicit Objects
  • JSP container provides you- the developer with
    tools necessary for your JSP document to interact
    with the environment surrounding it.
  • Of the implicit objects, there are three most
    used implicit objects that are used to handle the
    current session , the incoming request, and the
    outgoing response. These three are session,
    request, and response respectively.

11
Processing HTML Forms
  • JSP is a good replacement to the CGI scripts
    running behind the HTML forms.
  • JSP saves you the trouble of parsing the data
    coming from the client browser.
  • It takes just to call method request.getParameter(
    param-name) to get the data sent by the client
    browser.

12
JSP Directives
  • JSP Supports what is called JSP directives.
  • JSP directives are like SSI and not written in
    Java.
  • They look like
  • There are three directives defined by JSP
    include, page, and taglib
  • Examples
Write a Comment
User Comments (0)
About PowerShow.com