css"
type="text/css">
</head>
<body>
<%@ include file="/navbar.html" %>
<!-- part specific to this page ... -->
</body>
</html>
note that since the include directive inserts the files at the time the page is translated, if the navigation bar changes, you need to re-translate all the jsp pages that refer to it. this is a good compromise in a situation like this, since the navigation bar probably changes infrequently, and you want the inclusion process to be as efficient as possible. if, however, the included files changed more often, you could use the jsp:include action instead. this includes the file at the time the jsp page is requested, and is discussed in the tutorial section on jsp actions.
6. example using scripting elements and directives
here is a simple example showing the use of jsp expressions, scriptlets, declarations, and directives. you can also download the source or try it on-line.<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>using javaserver pages</title>
<meta name="author" content="marty hall -- hall@apl.jhu.edu">
<meta name="keywords"
content="jsp,javaserver pages,servlets">
<meta name="description"
content="a quick example of the four main jsp tags.">
<link rel=stylesheet
href="my-style-sheet.css"
type="text/css">
</head>
<body bgcolor="#fdf5e6" text="#000000" link="#0000ee"
vlink="#551a8b" alink="#ff0000">
<center>
<table border=5 bgcolor="#ef8429">
<tr><th class="title">
using javaserver pages</table>
</center>
<p>
some dynamic content created using various jsp mechanisms:
<ul>
<li><b>expression.</b><br>
your hostname: <%= request.getremotehost() %>.
<li><b>scriptlet.</b><br>
<% out.println("attached get data: " +
request.getquerystring()); %>
<li><b>declaration (plus expression).</b><br>
<%! private int accesscount = 0; %>
accesses to page since server reboot: <%= ++accesscount %>
<li><b>directive (plus expression).</b><br>
<%@ page import = "java.util.*" %>
current date: <%= new date() %>
</ul>
</body>
</html>
here's a typical result:
7. predefined variables
to simplify code in jsp expressions and scriptlets, you are supplied with eight automatically defined variables, sometimes called implicit objects. the available variables arerequest, response, out, session, application, config, pagecontext, and page. details for each are given below.
7.1 request
this is thehttpservletrequest associated with the request, and lets you look at the request parameters (via getparameter), the request type (get, post, head, etc.), and the incoming http headers (cookies, referer, etc.). strictly speaking, request is allowed to be a subclass of servletrequest other than httpservletrequest, if the protocol in the request is something other than http. this is almost never done in practice.
7.2 response
this is thehttpservletresponse associated with the response to the client. note that, since the output stream (see out below) is buffered, it is legal to set http status codes and response headers, even though this is not permitted in regular servlets once any output has been sent to the client.
7.3 out
this is theprintwriter used to send output to the client. however, in order to make the response object (see the p