JavaServer Pages (JSP) is a Java Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities. Java applications are typically compiled to bytecode (class file) technology that helps software developers A software developer is a person or organization concerned with facets of the software development process. They can be involved in aspects wider than design and coding, a somewhat broader scope of computer programming or a specialty of project managing including some aspects of software product management. This person may contribute to the serve dynamically generated web pages A dynamic web page is a hypertext document rendered to a World Wide Web user presenting content that has been customized or actualized for each individual viewing or rendition or that continually updates information as the page is displayed to the user. It is difficult to be precise about "dynamic web page beginnings" or chronology, based on HTML HTML, which stands for HyperText Markup Language, is the predominant markup language for web pages. It is written in the form of HTML elements consisting of "tags" surrounded by angle brackets within the web page content, XML Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards, or other document types. Released in 1999 as Java's answer to ASP Active Server Pages , also known as Classic ASP or ASP Classic, was Microsoft's first server-side script engine for dynamically-generated web pages. Initially released as an add-on to Internet Information Services (IIS) via the Windows NT 4.0 Option Pack, it was subsequently included as a free component of Windows Server (since the initial release and PHP PHP: Hypertext Preprocessor is a widely used, general-purpose scripting language that was originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document. As a general-purpose[1], JSP was designed to address the perception that the Java programming environment didn't provide developers with enough support for the Web.
Contents |
Overview
Architecturally, JSP may be viewed as a high-level abstraction of Java servlets Servlets are Java programming language objects that dynamically process requests and construct responses. The Java Servlet API allows a software developer to add dynamic content to a Web server using the Java platform. The generated content is commonly HTML, but may be other data such as XML. Servlets are the Java counterpart to non-Java dynamic. JSP pages are loaded in the server and operated from a structured special installed Java server packet called a Java EE Web Application, often packaged as a .war or .ear file archive.
JSP allows Java code and certain pre-defined actions to be interleaved with static web markup content, with the resulting page being compiled and executed on the server to deliver an HTML or XML document. The compiled pages and any dependent Java libraries use Java bytecode rather than a native software format, and must therefore be executed within a Java virtual machine A Java Virtual Machine enables a set of computer software programs and data structures to use a virtual machine model for the execution of other computer programs and scripts. The model used by a JVM accepts a form of computer intermediate language commonly referred to as Java bytecode. This language conceptually represents the instruction set of (JVM) that integrates with the host operating system An operating system is the software on a computer that manages the way different programs use its hardware, and regulates the ways that a user controls the computer. Operating systems are found on almost any device that contains a computer with multiple programs—from cellular phones and video game consoles to supercomputers and web servers. Some to provide an abstract platform-neutral environment.
JSP syntax is a fluid mix of two basic content forms: scriptlet elements and markup. Markup is typically standard HTML or XML, while scriptlet elements are delimited blocks of Java code which may be intermixed with the markup. When the page is requested the Java code is executed and its output is added, in situ, with the surrounding markup to create the final page. Because Java is a compiled language, not a scripting language, JSP pages must be compiled to Java bytecode classes before they can be executed, but such compilation generally only occurs once each time a change to the source JSP file occurs.
Java code is not required to be complete (self contained) within its scriptlet element block, but can straddle markup content providing the page as a whole is syntactically correct (for example, any Java if/for/while blocks opened in one scriptlet element must be correctly closed in a later element for the page to successfully compile). This system of split inline coding sections is called step over scripting because it can wrap around the static markup by stepping over it. Markup which falls inside a split block of code is subject to that code, so markup inside an if block will only appear in the output when the if condition evaluates to true; likewise markup inside a loop construct may appear multiple times in the output depending upon how many times the loop body runs.
The JSP syntax adds additional XML Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards-like tags, called JSP actions, 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 In computing, cross-platform, or multi-platform, is an attribute conferred to computer software or computing methods and concepts that are implemented and inter-operate on multiple computer platforms. Cross-platform software may be divided into two types; one requires individual building or compilation for each platform that it supports, and the way of extending the capabilities of a web server A web server is a computer program that delivers content, such as web pages, using the Hypertext Transfer Protocol (HTTP), over the World Wide Web. The term web server can also refer to the computer or virtual machine running the program. Note that not all company makes of Java servers are Java EE specification compliant.
Starting with version 1.2 of the JSP specification, JavaServer Pages have been developed under the Java Community Process The Java Community Process or JCP, established in 1998, is a formalized process that allows interested parties to get involved in the definition of future versions and features of the Java platform. 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 2010 · January | February | March | April | May | June | July | August | September | October | November | December the JSP 2.1 specification has been released under JSR 245 as part of Java EE Java Platform, Enterprise Edition or Java EE is a widely used platform for server programming in the Java programming language. The Java platform differs from the Java Standard Edition Platform (Java SE) in that it adds libraries which provide functionality to deploy fault-tolerant, distributed, multi-tier Java software, based largely on modular 5.
Example
JSPs are compiled into servlets Servlets are Java programming language objects that dynamically process requests and construct responses. The Java Servlet API allows a software developer to add dynamic content to a Web server using the Java platform. The generated content is commonly HTML, but may be other data such as XML. Servlets are the Java counterpart to non-Java dynamic 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 Bytecode is a term which has been used to denote various forms of instruction sets designed for efficient execution by a software interpreter as well as being suitable for further compilation into machine code. Since instructions are processed by software, they may be arbitrarily complex, but are nonetheless often akin to traditional hardware which is directly executable. JSPs can also be interpreted JSP Weaver is a JavaServer Pages interpreter. Unlike JSP compilers it evaluates the JSP files directly, without generating or compiling intermediate Java source files for the JSP Java servlet 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" %>
import …
class _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 (among other things).
- A faster/easier way to display parameter values.
- A clearer way to navigate nested beans.
The Java EE Java Platform, Enterprise Edition or Java EE is a widely used platform for server programming in the Java programming language. The Java platform differs from the Java Standard Edition Platform (Java SE) in that it adds libraries which provide functionality to deploy fault-tolerant, distributed, multi-tier Java software, based largely on modular 5 Platform has focused on easing development by making use of Java language annotations An annotation is a summary made of information in a book, document, online record, video, software code or other information, "in the margin", or perhaps just underlined or highlighted passages. Annotated bibliographies, give descriptions about how each source is useful to an author in constructing a paper or argument. Creating these 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 JavaServer Faces is a Java-based Web application framework intended to simplify development integration of web-based user interfaces (JSF), and the JavaServer Pages Standard Tag Library (JSTL).
The outcome of this 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
| Java portal |
- JSTL The JavaServer Pages Standard Tag Library , is a component of the Java EE Web application development platform. It extends the JSP specification by adding a tag library of JSP tags for common tasks, such as XML data processing, conditional execution, loops and internationalization. JSTL was developed under the Java Community Process (JCP) as JSR 52
- Java Servlet Servlets are Java programming language objects that dynamically process requests and construct responses. The Java Servlet API allows a software developer to add dynamic content to a Web server using the Java platform. The generated content is commonly HTML, but may be other data such as XML. Servlets are the Java counterpart to non-Java dynamic
- WAR (Sun file format)
- EAR (file format)
- JAR (file format) In computing software, a JAR file aggregates many files into one. Software developers generally use .jar files to distribute Java applications or libraries, in the form of classes and associated metadata and resources (text, images, etc.) JAR files build on the ZIP file format. Computer users can create or extract JAR files using the jar command
- Apache Tomcat Apache Tomcat is a servlet container developed by the Apache Software Foundation . Tomcat implements the Java Servlet and the JavaServer Pages (JSP) specifications from Sun Microsystems, and provides a "pure Java" HTTP web server environment for Java code to run
- Sun Java System Web Server
- ASP Active Server Pages , also known as Classic ASP or ASP Classic, was Microsoft's first server-side script engine for dynamically-generated web pages. Initially released as an add-on to Internet Information Services (IIS) via the Windows NT 4.0 Option Pack, it was subsequently included as a free component of Windows Server (since the initial release
- CFM ColdFusion is a commercial rapid application development platform invented by Jeremy and JJ Allaire in 1995. Originally designed to make it easier to connect simple HTML pages to a database, by version 2 it had become a full platform that included an IDE in addition to a full Scripting Language. Current versions of ColdFusion, sold by Adobe
- JHTML JHTML stands for Java HTML. This is a page authoring system developed at Art Technology Group . Files with a ".jhtml" filename extension contain standard HTML tags in addition to proprietary tags that reference Java objects running on a special server setup to handle requests for pages of this sort
Further reading
- Bergsten, Hans (2003). JavaServer Pages (3rd Edition ed.). O'Reilly Media O'Reilly Media is an American media company established by Tim O'Reilly that publishes books and web sites and produces conferences on computer technology topics. Their distinctive brand features a woodcut of an animal on many of their book covers. ISBN The International Standard Book Number is a unique numeric commercial book identifier based upon the 9-digit Standard Book Numbering (SBN) code created by Gordon Foster, now Emeritus Professor of Statistics at Trinity College, Dublin, for the booksellers and stationers W.H. Smith and others in 1966 978-0-596-00563-4.
- Hanna, Phil. JSP 2.0 - The Complete Reference. McGraw-Hill Osborne Media. ISBN The International Standard Book Number is a unique numeric commercial book identifier based upon the 9-digit Standard Book Numbering (SBN) code created by Gordon Foster, now Emeritus Professor of Statistics at Trinity College, Dublin, for the booksellers and stationers W.H. Smith and others in 1966 978-0-072-22437-5.
- Kathy, Sierra; Bert Bates & Bryan Basham. Head First Servlets & JSP. O'Reilly Media O'Reilly Media is an American media company established by Tim O'Reilly that publishes books and web sites and produces conferences on computer technology topics. Their distinctive brand features a woodcut of an animal on many of their book covers. ISBN The International Standard Book Number is a unique numeric commercial book identifier based upon the 9-digit Standard Book Numbering (SBN) code created by Gordon Foster, now Emeritus Professor of Statistics at Trinity College, Dublin, for the booksellers and stationers W.H. Smith and others in 1966 978-0-596-00540-5.
References
External links
| Wikibooks has a book on the topic of Java Programming/JSP |
- Sun's JSP product description
- Learn JSP Tutorial - step by step
- JSR 245 (JSP 2.1)
- JSR 152 (JSP 2.0)
- JSR 53 (JSP 1.2)
- JSP 1.1 and 1.0
- JSP tutorials with source code
- Quick JSP tutorial
- JSP training courses Public courses co-sponsored by Johns Hopkins University, or customized onsite versions
- Beginners JSP tutorial
- Core Servlets and JavaServer Pages
- JSP Tutorials
Categories: Java enterprise platform | Java specification requests |
|