World Library  
Flag as Inappropriate
Email this Article

JavaServer Pages


JavaServer Pages

Filename extension .jsp
Internet media type application/jsp
Latest release
Standard JSR 245
Website JavaServer Pages Technology

JavaServer Pages (JSP) is a technology that helps software developers create dynamically generated web pages based on HTML, XML, or other document types. Released in 1999 by Sun Microsystems,[1] JSP is similar to PHP, but it uses the Java programming language.

To deploy and run JavaServer Pages, a compatible web server with a servlet container, such as Apache Tomcat or Jetty, is required.


  • Overview 1
  • Syntax 2
    • Expression Language 2.1
    • Additional tags 2.2
  • Compiler 3
  • Criticism 4
  • See also 5
    • Servlet containers 5.1
    • Java-based alternative 5.2
  • References 6
  • Further reading 7
  • External links 8


The JSP Model 2 architecture.

Architecturally, JSP may be viewed as a high-level abstraction of Java servlets. JSPs are translated into servlets at runtime; each JSP servlet is cached and re-used until the original JSP is modified.[2]

JSP can be used independently or as the view component of a server-side model–view–controller design, normally with JavaBeans as the model and Java servlets (or a framework such as Apache Struts) as the controller. This is a type of Model 2 architecture.[3]

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 a document. The compiled pages, as well as any dependent Java libraries, use Java bytecode rather than a native software format. Like any other Java program, they must be executed within a Java virtual machine (JVM) that integrates with the server's host operating system to provide an abstract platform-neutral environment.

JSPs are usually used to deliver HTML and XML documents, but through the use of OutputStream, they can deliver other types of data as well.[4]

The Web container creates JSP implicit objects like pageContext, servletContext, session, request & response.


JSP pages use several delimiters for scripting functions. The most basic is <% ... %>, which encloses a JSP scriptlet. A scriptlet is a fragment of Java code that is run when the user requests the page. Other common delimiters include <%= ... %> for expressions, where the scriptlet and delimiters are replaced with the result of evaluating the expression, and directives, denoted with <%@ ... %>.[5]

Java code is not required to be complete or 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. 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 following would be a valid for loop in a JSP page:

Counting to three:

<% for (int i=1; i<4; i++) { %>

This number is <%= i %>.

<% } %>


The output displayed in the user's web browser would be:

Counting to three:

This number is 1.

This number is 2.

This number is 3.


Expression Language

Version 2.0 of the JSP specification added support for the Expression Language (EL), used to access data and functions in Java objects. In JSP 2.1, it was folded into the Unified Expression Language, which is also used in JavaServer Faces.[6]

An example of EL syntax:

The value of "variable" in the object "javabean" is ${javabean.variable}.

Additional tags

The JSP syntax adds additional tags, called JSP actions, to invoke built-in functionality.[5] Additionally, the technology allows for the creation of custom JSP tag libraries that act as extensions to the standard JSP syntax.[7] One such library is the JSTL, with support for common tasks such as iteration and conditionals (the equivalent of "for" and "if" statements in Java.)[8]


A JavaServer Pages compiler is a program that parses JSPs, and transforms them into executable Java Servlets. A program of this type is usually embedded into the application server and run automatically the first time a JSP is accessed, but pages may also be precompiled for better performance, or compiled as a part of the build process to test for errors.[9]

Some JSP containers support configuring how often the container checks JSP file timestamps to see whether the page has changed. Typically, this timestamp would be set to a short interval (perhaps seconds) during software development, and a longer interval (perhaps minutes, or even never) for a deployed Web application.[10]


In 2000, Jason Hunter, author of "Java Servlet Programming", criticized JSP for either tempting or requiring the programmer to mix Java code and HTML markup, although he acknowledged it would "wean people off" of Microsoft's Active Server Pages. Later, he added a note to his site saying that JSP had improved since 2000, but also cited its competitors, Apache Velocity and Tea.[11]

See also

Servlet containers

Java-based alternative


  1. ^ Mailing list archive: "Sun JSP 1.0 *not* available"
  2. ^ The Life Cycle of a JSP Page (Sun documentation)
  3. ^ Understanding JavaServer Pages Model 2 architecture (JavaWorld)
  4. ^ Forum thread (JavaRanch): OutputStream already obtained
  5. ^ a b JSP 1.1 Syntax Reference
  6. ^ The Unified Expression Language (Sun Developer Network)
  7. ^ Tag Libraries Tutorial - What is a Tag Library? (Sun)
  8. ^ JSTL documentation (Oracle)
  9. ^ IBM WebSphere 6.0.2 documentation
  10. ^ Sybase EAServer 5.0 documentation
  11. ^ The Problems with JSP (January 25, 2000)

Further reading

  • Bergsten, Hans (2003). JavaServer Pages (3rd Edition ed.).  
  • Hanna, Phil. JSP 2.0 - The Complete Reference.  
  • Sierra, Kathy; Bert Bates & Bryan Basham. Head First Servlets & JSP.  
  • Brown, Simon; Sam Dalton; Daniel Jepp; Dave Johnson; Sing Li; Matt Raible. Pro JSP 2.  

External links

  • Official tutorial: The Java EE 5 Tutorial, Chapter 5, JavaServer Pages Technology
  • JSP tutorials with source code
  • JSP v2.0 Syntax Reference
  • JavaServer Pages v2.0 Syntax Card (html)
  • Servlet History « Jim Driscoll's Blog
This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.

Copyright © World Library Foundation. All rights reserved. eBooks from Project Gutenberg are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.