simple site is usually the responsibility of Web page authors, who often do not have
such programming skills. The introduction of the JavaServer Pages technology
attempts to return the job of Web page authoring to those people whose responsibil-
ity it is, whilst the Java programmers maintain responsibility for the software com-
ponents used upon the Web pages. Using JSPs rather than servlets also removes the
rather tedious repetition of out.println for HTML tags.
However, the original JSP API still required Web page authors to supply small
'snippets' of Java code in their JSPs. Since those early days, much work has gone
into producing additional HTML-style tags that will further reduce the amount of
programming required in JSPs. The major output of this effort has been the
JavaServer Pages Standard Tag Library (JSTL) , which was developed by the
JSR-052 expert group as part of the Java Community Process. JSTL provides sup-
port for iterations, conditions, the processing of XML documents, internationalisa-
tion and database access using SQL. At its heart is Expression Language (EL),
which is designed specifi cally for Web authors, and an enhanced version of EL was
integrated into the JSP 2.0 specifi cation. The latest version of JSTL at the time of
writing is 1.2, which was released as long ago as May of 2006. JSTL 1.2 was inte-
grated into the Java EE 5 platform and is present in Java EE 6, though no further
development appears to have been made. Coverage of JSTL goes beyond the scope
of this text, however, and no further mention will be made of it.
Although the remainder of this chapter will be devoted to the use of scripting
within JSPs, it is worth pointing out that the use of scripting code should be kept to
a minimum. It is also worth mentioning in passing that such scripting code may
Java is the natural vehicle to use.
JSPs don't make servlets redundant. Servlets are still useful for supplying overall
control to all/part of a Web site. This is achieved by a servlet receiving HTTP
requests, determining what action to take, carrying out the necessary background
processing (e.g., opening up a connection to a remote database) and then passing
control to a JSP or ordinary HTML page that provides the response to the initial
browser request. This last stage may involve the servlet selecting the appropriate
page from a number of possible pages. Thus, servlets and JSPs may be used together
in a complementary and harmonious manner.
Before we consider the structure and contents of a JSP, we shall examine what
happens behind the scenes when a JSP is called up by a server…
Compilation and Execution
JSPs are held in the same Web application server folder as that holding HTML fi les.
(For Tomcat, of course, this means the root folder of the Web application.) When a
JSP is fi rst referenced by a Web server, it is actually converted into a servlet. This
servlet is then compiled and the compiled code stored on the server for subsequent
referencing. (For Tomcat, this compiled code is stored in <CATALINA_HOME>\
work .) If the referencing by the server was in response to a request for the JSP from