Wejp 2503 Unit III Jsp s5 Mca Students

Preview:

Citation preview

8/4/2019 Wejp 2503 Unit III Jsp s5 Mca Students

http://slidepdf.com/reader/full/wejp-2503-unit-iii-jsp-s5-mca-students 1/22

Java Server Pages

8/4/2019 Wejp 2503 Unit III Jsp s5 Mca Students

http://slidepdf.com/reader/full/wejp-2503-unit-iii-jsp-s5-mca-students 2/22

JAVA SERVER PAGES

Servlets are pure Java programs. They introducedynamism into web pages by using programmatic content.

JSP technology is an extension/wrapper over the Javaservlet technology.

JSP are text based documents.

We will focus only on JSP since it subsumes the servlettechnology.

Two major components of JSP:

1. Static content: provided by HTML or XML

2. Dynamic content: generated by JSP tags andscriplets written in Java language to encapsulate the

application logic.

8/4/2019 Wejp 2503 Unit III Jsp s5 Mca Students

http://slidepdf.com/reader/full/wejp-2503-unit-iii-jsp-s5-mca-students 3/22

What do you mean by Static & Dynamic

Contents?

Static contents

  Typically static HTML page

  Same display for everyone

Dynamic contents  Contents is dynamically generated based on conditions.

  Conditions could be

  User identity.

  Time of the day.  User entered values through forms and selections.

8/4/2019 Wejp 2503 Unit III Jsp s5 Mca Students

http://slidepdf.com/reader/full/wejp-2503-unit-iii-jsp-s5-mca-students 4/22

JSP compilation into Servlets

8/4/2019 Wejp 2503 Unit III Jsp s5 Mca Students

http://slidepdf.com/reader/full/wejp-2503-unit-iii-jsp-s5-mca-students 5/22

More on JSP syntax and contents

HTML code for user interface lay outJSP tags:

Declarations ± Java declarations

 Actions

Directives-page/include/taglib

Expressions- Java Expressions

Scriplets-Java Statements

JSP implicit objects: a request object, response object,session object, config object

Javabeans: for logic that can be taken care of at theJSP level.

8/4/2019 Wejp 2503 Unit III Jsp s5 Mca Students

http://slidepdf.com/reader/full/wejp-2503-unit-iii-jsp-s5-mca-students 6/22

JSP & Servlet as Web Components

8/4/2019 Wejp 2503 Unit III Jsp s5 Mca Students

http://slidepdf.com/reader/full/wejp-2503-unit-iii-jsp-s5-mca-students 7/22

What is JSP Page?

A text-based document capable of returning both static anddynamic content to a client browser.

Static content and dynamic content can be intermixed.

Static content

  HTML, XML, Text

Dynamic content

  Java code  Displaying properties of JavaBeans

  Invoking business logic defined in Custom tags

8/4/2019 Wejp 2503 Unit III Jsp s5 Mca Students

http://slidepdf.com/reader/full/wejp-2503-unit-iii-jsp-s5-mca-students 8/22

A Simple JSP Page

<html>

<body bgcolor="pink">

Hello World!

<br>

<centre><h2>Current time is <%= new java.util.Date()%>

</body></html>

8/4/2019 Wejp 2503 Unit III Jsp s5 Mca Students

http://slidepdf.com/reader/full/wejp-2503-unit-iii-jsp-s5-mca-students 9/22

Output

8/4/2019 Wejp 2503 Unit III Jsp s5 Mca Students

http://slidepdf.com/reader/full/wejp-2503-unit-iii-jsp-s5-mca-students 10/22

Servlets vs. JSP

ServletsServlets JSPJSP

HTML code in Java

Not easy to author� Java like code in HTML

Very easy to author Code is compiled into

a servlet

8/4/2019 Wejp 2503 Unit III Jsp s5 Mca Students

http://slidepdf.com/reader/full/wejp-2503-unit-iii-jsp-s5-mca-students 11/22

JSP Benefits

8/4/2019 Wejp 2503 Unit III Jsp s5 Mca Students

http://slidepdf.com/reader/full/wejp-2503-unit-iii-jsp-s5-mca-students 12/22

JSP BenefitsOver Competing Technologies -Versus

.NET & ASP

8/4/2019 Wejp 2503 Unit III Jsp s5 Mca Students

http://slidepdf.com/reader/full/wejp-2503-unit-iii-jsp-s5-mca-students 13/22

JSP BenefitsOver Competing Technologies

8/4/2019 Wejp 2503 Unit III Jsp s5 Mca Students

http://slidepdf.com/reader/full/wejp-2503-unit-iii-jsp-s5-mca-students 14/22

JSP Lifecycle

When a HTTP request is mapped to a JSP page, it is handled by a special built-inservlet (that is provided by a container) that first checks whether the JSP

page's servlet is older than the JSP page. If it is, the container translates the JSP

page into a servlet Java code and compiles the servlet code into servlet class.

And this is done automatically by the container. This is one of the advantages

of using JSP over servlet from developer standpoint.

8/4/2019 Wejp 2503 Unit III Jsp s5 Mca Students

http://slidepdf.com/reader/full/wejp-2503-unit-iii-jsp-s5-mca-students 15/22

JSP Page Lifecycle Phases

8/4/2019 Wejp 2503 Unit III Jsp s5 Mca Students

http://slidepdf.com/reader/full/wejp-2503-unit-iii-jsp-s5-mca-students 16/22

JSP Page Lifecycle Phases -Translation/Compilation

8/4/2019 Wejp 2503 Unit III Jsp s5 Mca Students

http://slidepdf.com/reader/full/wejp-2503-unit-iii-jsp-s5-mca-students 17/22

Translation/Compilation (Contd.)

8/4/2019 Wejp 2503 Unit III Jsp s5 Mca Students

http://slidepdf.com/reader/full/wejp-2503-unit-iii-jsp-s5-mca-students 18/22

JSP Page Lifecycle Phases -Execution

Once the page has been translated and compiled, the JSP page's servlet for the most part

follows the servlet life cycle as following:

1. If an instance of the JSP page's servlet does not exist, the container Loads the JSP page'sservlet class

2. Container then creates an instance of the servlet class

3. Container then initializes the servlet instance by calling the jspInit method

4. Container invokes the _jspService() method, passing a request and response object.

If the container needs to remove the JSP page's servlet, it calls the jspDestroy() method.

8/4/2019 Wejp 2503 Unit III Jsp s5 Mca Students

http://slidepdf.com/reader/full/wejp-2503-unit-iii-jsp-s5-mca-students 19/22

API for the generated Servlet

8/4/2019 Wejp 2503 Unit III Jsp s5 Mca Students

http://slidepdf.com/reader/full/wejp-2503-unit-iii-jsp-s5-mca-students 20/22

Initialization of a JSP Page

8/4/2019 Wejp 2503 Unit III Jsp s5 Mca Students

http://slidepdf.com/reader/full/wejp-2503-unit-iii-jsp-s5-mca-students 21/22

Finalization of a JSP Page

8/4/2019 Wejp 2503 Unit III Jsp s5 Mca Students

http://slidepdf.com/reader/full/wejp-2503-unit-iii-jsp-s5-mca-students 22/22

Recommended