JavaServer Pages
Just as this book was going to press, Sun announced a new way to use servlets, called JavaServer Pages (commonly, but not officially, referred to as JSP). JSP’s functionality and syntax bear a remarkable resemblance to Active Server Pages (ASP).
JSP operates in many ways like server-side includes. The main
difference is that instead of embedding a
SERVLET
tag in an HTML page, JSP embeds
actual snippets of servlet code. It’s an attempt by Sun to
separate content from presentation, more convenient than server-side
includes for pages that have chunks of dynamic content intermingled
with static content in several different places.
Just like server-side includes and servlet chaining, JSP doesn’t require any changes to the Servlet API. But it does require special support in your web server. This support is not included in the Java Web Server 1.1.1 (the unofficially considered reference servlet engine against which this book is written), but it’s expected to be introduced in the next version of the Java Web Server, probably 1.2, and in other servlet engines as they keep pace.
Note that the following tutorial is based on the JavaServer Pages draft specification, version 0.91. You may notice small changes in the final specification.
Using JavaServer Pages
At its most basic, JSP allows for the direct insertion of servlet
code into an otherwise static HTML file. Each block of servlet code
(called a scriptlet) is surrounded by a leading
<%
tag and a closing %>
tag.[10] For convenience, ...
Get Java Servlet Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.