3.6.1.1 JSP directives
JSP directive tags define the attributes that apply to the entire JSP page. We
used
<%@ LANGUAGE= Java %>
in our JSP pages, indicating that we will use
Java as the default language. Figure 72 shows a portion of our logout.jsp file.
Note that the JSP directive is located at the beginning of the file.
<%@ LANGUAGE="Java" %>
charset=ISO 8859 1">
MainPage
Figure 72. Portion of logout.jsp
A complete listing of all relevant JSP directives can be obtained from Sun's
JSP page at:
http://java.sun.com/products/jsp
3.6.1.2 Inline scripts
You can embed any valid Java code within a JSP file between the
<%
and
%>
tags. The Java codes can be intermingled with the HTML. Figure 73
illustrates how we embed HTML and Java into the JSP file.
HomePage
<% HttpSession session=request.getSession(true);
if (session.getValue("error") !=null){ %>
ERROR:
<% out.println(session.getValue("error"));
}
session.removeValue("error");
%>
Figure 73. Embedded HTML and Java in a JSP file
In Figure 73, we embedded the HTML by ensuring that we enclosed the
preceding Java statement with
<% %>
, provide some HTML codes, and then
Chapter 3. Building the Web server
99