Download Overview of JSP Technology

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Overview of JSP Technology
The need of JSP
With servlets, it is easy to
– Read form data
– Read HTTP request headers
– Set HTTP status codes and response headers
– Use cookies and session tracking
– Share data among servlets
– Remember data between requests
– set up custom code to handle missing and malformed data
• But, Servlets are not so good at presentation
– It is hard to write and maintain the HTML using println()
statements.
– The HTML is inaccessible to non-Java developers
– You cannot use standard HTML tools
What is JSP?
Java Server Pages(JSP) technology is used to create dynamic web
pages and which enables you to mix regular static HTML with
dynamically generated content.
– Use regular HTML for most of page
– Enclose servlet code( for dynamic part) with special tags
– Entire JSP page gets translated into a servlet (once), and servlet is
what actually gets invoked (for each request)
• Example:
<HTML>
<HEAD>
<TITLE>Order Confirmation</TITLE>
</HEAD>
<BODY>
<H2>Order Confirmation</H2>
Thanks for ordering
<I><%= request.getParameter("title") %></I>!
</BODY></HTML>
Benefits of JSP
JSP provides the following benefits over servlets alone.
• JSP makes it easier to:
– Write HTML
– Read and maintain the HTML
• JSP makes it possible to:
– Use standard HTML tools such as DreamWeaver
- Divide up your development team .
- Java developers can concentrate on dynamic code and
web developers can concentrate on the presentation
layer.
• JSP encourages you to
– Separate the (Java) code that creates the content from
the (HTML) code that presents it
Advantages of JSP Over Competing Technologies
Versus .NET and Active Server Pages
– Better language for dynamic part
– Portable to multiple servers and operating systems
- Since the dynamic part of Jsp written in java, Jsp is more
powerful and suited to complex applications that
require reusable components
• Versus PHP
– dynamic part of JSP is written in Java, which has an
extensive API for networking, database access,
distributed objects, whereas PHP requires learning an
entirely new, less widely used language
– JSP more widely supported by tool
•Versus Velocity or WebMacro
– Standardization, portability, Tremendous industry
support
JSP specifications define a standard directory
structure for web applications and provide standard
files for deploying web application.
• Versus client-side JavaScript (in browser)
– Javascript capabilities mostly do not overlap with
JSP(which runs only on the server)
- JSP pages include script tags for JavaScript
- Java Script is not a competing technology, it is a
complementary one
• Versus pure servlets
– More convenient to create HTML
– Can use standard tools (e.g., DreamWeaver)
– Easy to maintain because we can separate business
logic with presentation logic
– JSP programmers still need to know servlets for 4
reasons
-
1. JSP pages get translated into servlets. You can’t
understand how JSP works without understanding
servlets.
2. JSP consists of static HTML, special-purpose JSP tags,
and Java code(i.e Servlet code). You can’t write that
code if you don’t understand servlet programming.
3. Some tasks are better accomplished by servlets than by
JSP. JSP is good at generating pages that consist of large
sections of fairly well structured HTML or other
character data. Servlets are better for generating
binary data, and performing tasks (such as redirection)
that involve little or no output.
4. Some tasks are better accomplished by a combination
of servlets and JSP than by either servlets or JSP alone.
Basic Syntax
HTML Text
• Description:
HTML content to be passed unchanged to the client
• Example:
<H1>Blah</H1>
HTML Comments
• Description:
HTML comment that is sent to the client but not displayed by the
browser
• Example:
<!-- Blah -->
Template Text
• Description:
Text sent unchanged to the client. HTML text and HTML comments
are just special cases of this.
• Example:
Anything other than the syntax of the following subsections
JSP Comment
• Description:
Developer comment that is not sent to the client
• Example:
<%-- Blah --%>
JSP Expression
• Description:
Expression that is evaluated and sent to the client each time the page
is requested
• Example:
<%= Java Value %>
JSP Scriptlet
• Description:
Statement or statements that are executed each time the page is
requested
• Example: <% Java Statement %>
JSP Declaration
• Description:
Field or method that becomes part of class definition
when page is translated into a servlet
• Examples:
<%! Field Definition %>
<%! Method Definition %>
JSP Directive
• Description:
High-level information about the structure of the
servlet code (page),code that is included at pagetranslation time (include), or customtag libraries used
(taglib)
• Example:
<%@ directive att="val" %>
JSP Action
• Description:
Action that takes place when the page is requested
• Example:
<jsp:blah>...</jsp:blah>
JSP Expression Language Element
• Description:
Shorthand JSP expression
• Example:
${ EL Expression }
Custom Tag (Custom Action)
• Description:
Invocation of custom tag
• Example:
<prefix:name>
Body
</prefix:name>
Escaped Template Text
• Description:
Text that would otherwise be interpreted specially. Slash is
removed and remaining text is sent to the client
• Examples:
<\%
%\>