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, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access