6/12/2550

JavaServer Pages


JavaServer Pages (JSP) is a Java technology that allows software developers to dynamically generate HTML, XML or other types of documents in response to a Web client request. The technology allows Java code and certain pre-defined actions to be embedded into static content.

The JSP syntax adds additional XML-like tags, called JSP actions, to be used to invoke built-in functionality. Additionally, the technology allows for the creation of JSP tag libraries that act as extensions to the standard HTML or XML tags. Tag libraries provide a platform independent way of extending the capabilities of a Web server.

JSPs are compiled into Java Servlets by a JSP compiler. A JSP compiler may generate a servlet in Java code that is then compiled by the Java compiler, or it may generate byte code for the servlet directly.

JSP and Servlets
Architecturally speaking, JSP can be viewed as a high-level abstraction of servlets that is implemented as an extension of the Servlet 2.1 API. Both servlets and JSPs were originally developed at Sun Microsystems, initially created by Anselm Baird-Smith and later elaborated on as a specification by Satish Dharmaraj. Starting with version 1.2 of the JSP specification, JavaServer Pages have been developed under the Java Community Process. JSR 53 defines both the JSP 1.2 and Servlet 2.3 specifications and JSR 152 defines the JSP 2.0 specification. As of May 2006 the JSP 2.1 specification has been released under JSR 245 as part of Java EE 5.

JSP syntax
A JavaServer Page may be broken down into the following pieces:

* static data such as HTML,
* JSP directives such as the include directive,
* JSP scripting elements and variables,
* JSP actions,
* custom tags

JSP directives
JSP directives control how the JSP compiler generates the servlet. The following directives are available:

JSP actions
JSP actions are XML tags that invoke built-in web server functionality. They are executed at runtime. Some are standard and some are custom(which are developed by Java developers.) Following are the standard ones:

jsp:include
Similar to a subroutine, the Java servlet temporarily hands the request and response off to the specified JavaServer Page. Control will then return to the current JSP, once the other JSP has finished. Using this, JSP code will be shared between multiple other JSPs, rather than duplicated.
jsp:param
Can be used inside a jsp:include, jsp:forward or jsp:params block. Specifies a parameter that will be added to the request's current parameters.
jsp:forward
Used to hand off the request and response to another JSP or servlet. Control will never return to the current JSP.
jsp:plugin
Older versions of Netscape Navigator and Internet Explorer used different tags to embed an applet. This action generates the browser specific tag needed to include an applet.
jsp:fallback
The content to show if the browser does not support applets.
jsp:getProperty
Gets a property from the specified JavaBean.
jsp:setProperty
Sets a property in the specified JavaBean.
jsp:useBean
Creates or re-uses a JavaBean available to the JSP page.
Google