• 1
  • 2
Home > Tips

What is JSP? | Overview of JavaServer Pages


What is JSP? | Overview of JavaServer Pages


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, 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 of JavaServer Page (JSP)

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

JSP can be used independently or as the view component of a server-side modelCviewCcontroller 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.

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.



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 value of the expression is placed into the page delivered to the user, and directives, denoted with <%@ ... %>.

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:

 <p>Counting to three:</p>
<% for (int i=1; i<4; i++) { %>
    <p>This number is <%= i %>.</p>
<% } %>
<p>Done counting.</p>

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.
Done counting.

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.

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. Additionally, the technology allows for the creation of custom JSP tag libraries that act as extensions to the standard JSP syntax. One such library is the JSTL, with support for common tasks such as iteration and conditionals (the equivalent of 'if' and 'for' statements in Java.)


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.

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.

 Comparison with Similar Technologies

JSP pages are similar to PHP pages and ASP.NET Web Forms, in that all three add server-side code to an HTML page. However, all three terms refer to a different component of the system. JSP refers to the JSP pages, which can be used alone, with Java servlets, or with a framework such as Apache Struts. PHP is itself a programming language, designed for dynamic Web pages. ASP.net is a framework comparable to Struts or JavaServer Faces that uses pages called Web Forms.

While JSP pages use the Java language, ASP.NET pages can use any .NET-compatible language, usually C#.
ASP.NET is designed for a Microsoft Windows web server, while PHP and Java server technologies (including JSP) are fairly operating system agnostic.

 Caching to Improve Performance

The popularity of JavaServer Pages has meant that it is being used quite frequently in developing high-traffic web apps. And, this is causing performance bottlenecks as you try to add more users and transaction load on your JavaServer Pages application. Although, JavaServer Pages application can scale very nicely to multiple web servers, the database server cannot. The main reason for the database becoming a bottleneck is that while you can add more and more servers to the JavaServer Pages application server farm, you cannot do the same at the database tier. This results in limited scalability at the data tier. You can remove these JavaServer Pages Servlets performance bottlenecks by using a distributed cache for storing the frequently used data.


In 2000, Jason Hunter 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.


Choose a SliceMaker Product to Create a Website on Your Own-30 Day Freetrial
SliceMaker Standard V3.6 - Freeware
SliceMaker Standard V3.6 - Freeware
The anyone-can-master webpage making software. You can create exceptional webpage/website on your own even if you're unfamiliar with webpage making.
SliceMaker Platinum V3.6 - Freeware
SliceMaker Platinum V3.6 - Freeware
The bestselling webpage making software, helps you create exceptional webpage/website without writing complicated CSS and DIV codes.
SliceMaker Deluxe V3.6 - Freeware
SliceMaker Deluxe V3.6 - Freeware
The all-in-one webpage making software, helps you create webpage/website of any style. It's the idea tool to create webpage/website.