About JavaServer Pages
JavaServer
Pages (JSP) technology provides a quick, easy way to create Web
pages with both static and dynamic content. JSPs are text-based documents
that contain static markup, usually in HTML or XML, as well as Java
content in the form of scripts and/or calls to Java components. JSPs
extend the Java Servlet API and have access to all Java APIs and components.
You can use JSPs
in many ways in Web-based applications. As part of the J2EE application
model, JSPs typically run on a Web server in the middle tier, responding
to HTTP requests from clients, and invoking the business methods
of Enterprise JavaBeans (EJB) components on a transaction server.
JSP pages built with PowerBuilder 9 support version
1.2 of the JavaServer Pages specification and version 2.3 of the
Java Servlet specification. PowerBuilder 9 supports custom tag libraries
that use the JSP 1.2 format. You can choose to deploy a JSP target
as a Web application to EAServer 4.1x, Apache Tomcat 4.0 and later,
or any JSP 1.2 server for which you can configure command line deployment
capabilities.
For more information, see the JavaServer Pages specification
, and the Java Servlets specification
.
How JavaServer Pages work
JSP
pages are executed in a JSP engine (also called a JSP container)
that is installed on a Web or application server. The JSP engine
receives a request from a client and delivers it to the JSP page.
The JSP page can create or use other objects to create a response.
For example, it can forward the request to a servlet or an EJB component,
which processes the request and returns a response to the JSP page.
The response is formatted according to the template in the JSP page
and returned to the client.
Translating into a servlet class
In
PowerBuilder, JSP pages are deployed to the server in source form.
If a JSP page is in source form, the JSP engine typically translates
the page into a class that implements the servlet interface and
stores it in the server’s memory. Depending on the implementation
of the JSP engine, translation can occur at any time between initial
deployment and the receipt of the first request. As long as the
JSP page remains unchanged, subsequent requests reuse the servlet
class, reducing the time required for those requests.
Requests and responses
Some
JSP engines can handle requests and responses that use several different protocols,
but all JSP engines can handle HTTP requests and responses. The JspPage and HttpJspPage classes
in the javax.servlet.jsp package define the interface
for the compiled JSP, which has three methods:
- jspInit()
- jspDestroy()
- _jspService(HttpServletRequest
request, HttpServletResponse response)
What a JSP contains
A JSP contains static
template text that is written to the output stream. It also contains
dynamic content that can take several forms:
- Directives
provide global information for the page, or include a file of text or
code. - Scripting elements (declarations, scriptlets, and
expressions) manipulate objects and perform computations. - Standard tags, or actions, perform common actions
such as instantiating a JavaBeans component or getting or setting
its properties, downloading a plug-in, or forwarding a request. - Custom tags perform additional actions defined in
a custom tag library.
“JSP page authoring” provides
a brief description of each of these types of dynamic content. For
more detailed information, see the JavaServer Pages
, or one of the many books about JavaServer
Pages technology.
Application logic in JSPs
The application logic in
JSPs can be provided by components such as servlets, JavaBeans,
and EJBs, customized tag libraries, scriptlets, and expressions. Scriptlets
and expressions hold the components and tags together in the page.
JavaBeans
You can easily
use JavaBeans components in a JSP with the useBean tag.
For more information, see “<jsp:useBean>”.
Enterprise JavaBeans
To use an EJB component, you need to use JNDI to establish
an initial naming context for the EJB’s home interface.
You could do this in a scriptlet, using a JavaBeans component, or
using a custom tag.
Custom tag libraries
Custom
tag libraries define a set of actions to be used within a JSP for
a specific purpose, such as handling SQL requests. See “Custom tags”.