Java Server Pages

Java Server Pages

By Chris Eddy, OCI Senior Software Engineer

September 1999


What is JSP?

Java Server Pages (JSP) is a technology developed in collaboration between Sun Microsystems and web server industry giants BEA, Netscape, IBM, and others. 

JSP documents are server-side documents containing instructions that must be processed before being transmitted to the client. These instructions could be as simple as displaying the current time, or they could perform complex data retrieval and manipulation. JSP documents, therefore, are not "readable" by a client browser until they have been executed on the server for transfer to the client in a browser-friendly format, such as HTML or XML. 

JSP enables the rapid creation of dynamic web pages with reusable components. Since this technology is based on Java, it is platform independent, as well as server independent.

How does JSP fit into the typical Web Application?

The client sends a request to the web server, which recognizes the requested page as a JSP page. This is server dependent, but usually the extension on the page is the clue (such as .jhtml). 

The JSP page can contain references to shared bean components, as well as embedded Java code called "scriptlets." 

The WebServer parses the document, searching for specific "JSPTaglets" identifying the scriptlets. The code lying inside these taglets is parsed and compiled into the Servlet Engine, creating a servlet class file. 

This servlet then executes and returns a dynamically generated response that is devoid of any scriptlet code, having been replaced by the output from the servlet. 

On subsequent requests, the parse and compile steps are omitted, unless the JSP page is newer than the class file. Thus, the first call may be slow, but the following requests are fast, since the code has already been compiled and loaded into memory.

What are "Scriptlets"?

JSP scriptlets are written in the Java programming language. This language is essentially the same Java we all know and love, with a few minor enhancements to make coding scriptlets inside HTML easier.  

These changes include APIs to aid in the retrieval of request parameters, as well as methods to allow for invoking other JSPs. 

Scriptlets are embedded in the JSP document between JSPTaglets, marking the start and end of the scriptlet.

Can I use JavaBeans with JSP?

Through the BEAN tag, JSP allows access to JavaBeans.

The bean tag provides many attributes to configure how the bean is used. It is possible to have a JavaBean's properties updated directly from a submitted form, to limit a bean's scope to a single request or a complete session, and to name the bean.

How can I create and test JSP?

Sun provides a development and testing tool through its JavaServer Web Development Kit. This tool can serve JSP documents and servlets, as well as straight HTML documents, and it is free of charge. 

The tool essentially runs as a small webserver and servlet engine, providing a complete development and testing environment for JSP pages.

A Simple Sample

(This sample was run using the jswdk-1.0)

The JSP Page

  1. <html>
  2. <head>
  3. <title>Greetings</title>
  4. </head>
  5. <body>
  6. <%
  7. for (int i=0; i < 5; i++) out.println("<h1>This is EASY!!!</h1>");
  8. %>
  9. </body>
  10. </html>

This source sent back to the browser looks like this.

  1. <html>
  2. <head>
  3. <title>Greetings</title>
  4. </head>
  5. <body>
  6. <h1>This is EASY!!!</h1>
  7. <h1>This is EASY!!!</h1>
  8. <h1>This is EASY!!!</h1>
  9. <h1>This is EASY!!!</h1>
  10. <h1>This is EASY!!!</h1>
  11. </body>
  12. </html>

Who currently supports JSP implementations?

JSP is supported in products such as:



Software Engineering Tech Trends (SETT) is a regular publication featuring emerging trends in software engineering.


secret