Tuesday, April 7, 2009

JSP BASIC, Implicit objects, directives,scripting , action

JavaServer Pages:
(JSP)—an extension of servlet technology. JavaServer Pages simplify the delivery of dynamic Web content. They enable Web application programmers to create dynamic content by reusing predefined components and by interacting with components using serverside scripting
They are four key component to JSP:
1.directives
2. actions
3. scriptlets
4. tag libraries.
JSP Life cycle
Overall, the request/response mechanism and life cycle of a JSP is the same as that of a servlet. JSPs can define methods jspInit and jspDestroy (similar to servlet methods init and destroy), which the JSP container invokes when initializing a JSP and terminating a JSP, respectively. JSP programmers can define these methods using JSP declarations—part of the JSP scripting mechanism

Implicit Objects
Implicit objects provide programmers with access to many servlet capabilities in the context
of a JavaServer Page.
Implicit objects have four scopes:
  • application
  • page
  • request
  • session
Application Scope
application:
This javax.servlet.ServletContext object represents the container in
which the JSP executes.

Page Scope
config:
This javax.servlet.ServletConfig object represents the JSP configuration
options. As with servlets, configuration options can be specified in a
Web application descriptor.
exception:
This java.lang.Throwable object represents the exception that is passed
to the JSP error page. This object is available only in a JSP error page.

out:
This javax.servlet.jsp.JspWriter object writes text as part of the
response to a request. This object is used implicitly with JSP expressions and
actions that insert string content in a response.

page:
This java.lang.Object object represents the this reference for the current
JSP instance.

pageContext:
This javax.servlet.jsp.PageContext object hides the implementation
details of the underlying servlet and JSP container and provides JSP programmers
with access to the implicit objects discussed in this table.

response:
This object represents the response to the client and is normally an instance
of a class that implements HttpServletResponse (package javax.servlet.
http). If a protocol other than HTTP is used, this object is an instance
of a class that implements javax.servlet.ServletResponse.

Request Scope
request:
This object represents the client request. The object normally is an instance
of a class that implements HttpServletRequest (package javax.servlet.
http). If a protocol other than HTTP is used, this object is an instance
of a subclass of javax.servlet.ServletRequest.

Session Scope
session:
This javax.servlet.http.HttpSession object represents the client session
information if such a session has been created. This object is available
only in pages that participate in a session.

Directives:
Directives are messages to the JSP container that enable to include content from other resources and to specify custom-tag libraries for use in a JSP.
page Directive:
The page directive specifies global settings for the JSP in the JSP container.
include Directive:
The include directive includes the content of another resource once, at JSP translation time.
Tag Directives:
JSP offer a unique feature of “Tag Libraries”. Simply put, these are custom defined JSP tags.
Scripting:
JSP programmers can insert Java code and logic in a JSP
using scripting.
Scripting Components:
JSP scripting components include
  • scriptlets
  • comments
  • expressions
  • declarations
  • e scape sequences.
Standard Actions:
jsp:include :
Dynamically includes another resource in a JSP. As the JSP executes,
the referenced resource is included and processed.
jsp:forward :
Forwards request processing to another JSP, servlet or static page.
This action terminates the current JSP’s execution.
jsp:plugin:
Allows a plug-in component to be added to a page in the form of a
browser-specific object or embed HTML element.
jsp:param:
Used with the include, forward and plugin actions to specify
additional name/value pairs of information for use by these actions.
JavaBean Manipulation:
jsp:useBean:
Specifies that the JSP uses a JavaBean instance. This action specifies
the scope of the bean and assigns it an ID that scripting components
can use to manipulate the bean.
jsp:setProperty:
Sets a property in the specified JavaBean instance. A special feature
of this action is automatic matching of request parameters to bean
properties of the same name.
jsp:getProperty:
Gets a property in the specified JavaBean instance and converts the
result to a string for output in the response.

No comments:

Post a Comment

Search This Blog