Share on Facebook Share on Twitter Email
Answers.com

JavaServer Pages

 

(JavaServer Page) An extension to the Java servlet technology from Sun that allows HTML to be combined with Java on the same page. The Java provides the processing, and the HTML provides the layout on the Web page.

Dynamic Web Pages in J2EE

JSPs are the primary method in the J2EE platform for displaying dynamic Web pages. Special tags let Java code be included on the page as well as inserted into HTML statements without invalidating the HTML syntax. It thus lets non-Java programmers maintain HTML pages in their favorite authoring programs without interfering with the Java code on the page. With the use of standard and custom JSP tags, the Java code can be completely hidden (see JSTL and JSP tag).

From JSPs to Java Servlets

At runtime, the application server turns the JSP into a Java servlet (.jsp to .java file) using a JSP converter, which is a part of the servlet container. The servlet is then compiled into bytecode (.class) and run on the server like any other servlet.

The JSP can also call Enterprise JavaBeans (EJBs) for additional processing. JSPs are the Sun/Java counterpart to Microsoft's ASPs (Active Server Pages). See servlet and servlet container.

JSPs Run in the Server
JSPs and servlets are server-side applications that are standard features of the J2EE platform.

Download Computer Desktop Encyclopedia to your iPhone/iTouch

Search unanswered questions...
Enter a question here...
Search: All sources Community Q&A Reference topics
Wikipedia: JavaServer Pages
Top

JavaServer Pages (JSP) is a server side Java technology that allows software developers to create dynamically generated web pages, with HTML, XML, or other document types, in response to a Web client request to a Java Web Application container (server). Architecturally, JSP may be viewed as a high-level abstraction of Java servlets. JSP pages are loaded in the server and operated from a structured special installed Java server packet called a J2EE Web Application often packaged as a .war or .ear file archive.

The technology allows Java code and certain pre-defined actions to be embedded into static page content and compiled on the server at runtime of each page request. Both the Java Server (J2EE specification) and the page scripts and/or extended customised programming added operate by (in the runtime context of being loaded programs used) a special pre-installed base program called a virtual machine (VM) that integrates with the host operating system, this type being the Java Virtual Machine (JVM).

JSP syntax has two basic forms, scriptlet and markup though fundamentally the page is either HTML or XML markup. Scriptlet tagging (called Scriptlet Elements)(delimited) blocks of code with the markup are not effectively markup and allows any java server relevant API (e.g. the servers running binaries themselves or database connections API or java mail API) or more specialist JSP API language code to be embedded in an HTML or XML page provided the correct declarations in the JSP file and file extension of the page are used. Scriptlet blocks do not require to be completed in the block itself only the last line of the block itself being completed syntactically correctly as a statement is required, it can be completed in a later block. This system of split inline coding sections is called step over scripting because it can wrap around the static markup by stepping over it. At runtime (during a client request) the code is compiled and evaluated, but compilation of the code generally only occurs when a change to the code of the file occurs. 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. JVM operated Tag libraries provide a platform independent way of extending the capabilities of a web server. Note that not all company makes of Java servers are J2EE specification compliant.

Contents

History

The JSP 1.0 specification has been released in 1999 as the Java's answer to ASP and PHP.[1] Both servlets and JSPs were originally developed at Sun Microsystems. 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.

Example

JSPs are compiled into servlets by a JSP compiler. The compiler either generates a servlet in Java code that is then compiled by the Java compiler, or it may compile the servlet to byte code which is directly executable. JSPs can also be interpreted on-the-fly, reducing the time taken to reload changes.

Regardless of whether the JSP compiler generates Java source code for a servlet or emits the byte code directly, it is helpful to understand how the JSP compiler transforms the page into a Java servlet. For example, consider the following input JSP and its resulting generated Java Servlet.

Input JSP

 <%@ page errorPage="myerror.jsp" %>
 <%@ page import="com.foo.bar" %>
 
 <html>
 <head>
 <%! int serverInstanceVariable = 1;%>
 
 <% int localStackBasedVariable = 1; %>
 <table>
 <tr><td><%= toStringOrBlank( "expanded inline data " + 1 ) %></td></tr>

Resulting servlet

 package jsp_servlet;
 import java.util.*;
 import java.io.*;
 import javax.servlet.*;
 import javax.servlet.http.*;
 import javax.servlet.jsp.*;
 import javax.servlet.jsp.tagext.*;
 
 import com.foo.bar; // Imported as a result of <%@ page import="com.foo.bar" %>
 importclass _myservlet implements javax.servlet.Servlet, javax.servlet.jsp.HttpJspPage {
    // Inserted as a
    // result of <%! int serverInstanceVariable = 1;%>
    int serverInstanceVariable = 1;public void _jspService( javax.servlet.http.HttpServletRequest request,
    javax.servlet.http.HttpServletResponse response )
    throws javax.servlet.ServletException,
    java.io.IOException
    {
        javax.servlet.ServletConfig config =; // Get the servlet config
        Object page = this;
        PageContext pageContext =;            // Get the page context for this request
        javax.servlet.jsp.JspWriter out = pageContext.getOut();
        HttpSession session = request.getSession( true );
        try {
            out.print( "<html>\r\n" );
            out.print( "<head>\r\n" );// From <% int localStackBasedVariable = 1; %>
            int localStackBasedVariable = 1;
            …
            out.print( "<table>\r\n" );
            out.print( " <tr><td>" );
            // From <%= toStringOrBlank( "expanded inline data " + 1 ) %>
            out.print( toStringOrBlank( "expanded inline data " + 1 ) );
            out.print( " </td></tr>\r\n" );} catch ( Exception _exception ) {
            // Clean up and redirect to error page in <%@ page errorPage="myerror.jsp" %>
        }
    }
 }

JSP 2.0

The new version of the JSP specification includes new features meant to improve programmer productivity. Namely:

  • An Expression Language (EL) which allows developers to create Velocity-style templates (among other things).
  • A faster/easier way to display parameter values.
  • A clearer way to navigate nested beans.

In the Java EE 5 Platform, the focus has been ease of development by making use of Java language annotations that were introduced by J2SE 5.0. JSP 2.1 supports this goal by defining annotations for dependency injection on JSP tag handlers and context listeners.

Another key concern of the Java EE 5 specification has been the alignment of its webtier technologies, namely JavaServer Pages (JSP), JavaServer Faces (JSF), and JavaServer Pages Standard Tag Library (JSTL).

The outcome of this alignment effort has been the Unified Expression Language (EL), which integrates the expression languages defined by JSP 2.0 and JSF 1.1.

The main key additions to the Unified EL that came out of the alignment work have been: A pluggable API for resolving variable references into Java objects and for resolving the properties applied to these Java objects, support for deferred expressions, which may be evaluated by a tag handler when needed, unlike their regular expression counterparts, which get evaluated immediately when a page is executed and rendered, and support for l-value expression, which appear on the left hand side of an assignment operation. When used as an l-value, an EL expression represents a reference to a data structure, for example: a JavaBeans property, that is assigned some user input. The new Unified EL is defined in its own specification document, which is delivered along with the JSP 2.1 specification.

Thanks to the Unified EL, JSTL tags, such as the JSTL iteration tags, can now be used with JSF components in an intuitive way.

JSP 2.1 leverages the Servlet 2.5 specification for its web semantics.

See also

Further reading

References

  1. ^ JSP 1.0 specification

External links


 
 

 

Copyrights:

Computer Desktop Encyclopedia. THIS COPYRIGHTED DEFINITION IS FOR PERSONAL USE ONLY.
All other reproduction is strictly prohibited without permission from the publisher.
© 1981-2009 Computer Language Company Inc.  All rights reserved.  Read more
Wikipedia. This article is licensed under the Creative Commons Attribution/Share-Alike License. It uses material from the Wikipedia article "JavaServer Pages" Read more