Java Reference
In-Depth Information
Name Type
request javax.servlet.http.HttpServletRequest
response javax.servlet.http.HttpServletResponse
session javax.servlet.http.HttpSession
config javax.servlet.ServletConfig
application javax.servlet.ServletContext
out
javax.servlet.jsp.JspWriter
Example 18-4 begins with @page and @taglib directives. These are followed by a
declaration tag, which defines a simple password verification method. * The decla-
ration is followed by a scriptlet tag, which includes Java code that runs each time
the JSP page is requested. This code gets the login name and password from a
previous form submission (unless this is the first time the page is requested) and
attempts to verify the username and password. If the verification is successful, the
scriptlet stores the username in the servlet's session object and sends a redirect to
the user's browser, causing it to load whatever page was specified by the nextpage
request parameter.
If password verification is not successful, the scriptlet tag ends and a block of
HTML text follows. The HTML text creates the login form that allows the user to
enter a name and a password. The HTML tags are interspersed occasionally with
<%= . . . %> tags that contain Java expressions whose values are substituted into the
HTML output. The HTML code also contains the custom <decor:box> and
</decor:box> tags. This is an invocation of the box tag from the decor library
imported at the top of the page by the <%@taglib . . . %> directive. This custom tag
creates the bordered and titled box that appears in Figure 18-3. Later in the chap-
ter (in Example 18-9), you'll see how this tag is implemented and made available
to JSP pages. Note that JSP pages can also use a variety of tags with the jsp: pre-
fix. No @taglib directive is required to use these tags. This example does not use
them, but the next two examples do.
Example 18−4: login.jsp
<%--login.jsp
The next two lines are JSP directives. The page directive tells the JSP
compiler that this page contains Java (instead of JavaScript e.g.) code and
outputs HTML (instead of XML, e.g.). The second directive tells the JSP
compiler that this page uses a "tag library" with the specified unique
identifier and whose tags are prefixed (on this page) by the word "decor".
--%>
<%@page language='java' contentType='text/html'%>
<%@taglib uri='http://www.davidflanagan.com/tlds/decor_0_1.tld'
prefix='decor'%>
<%--
The code below is in a <%!...%> declaration block. When this JSP page
is compiled to a servlet, this code is used to define members of the
Servlet class.
--%>
* This verify() method is included here to demonstrate how Java methods can be included in JSP pages.
In production code, this method should be placed in an external class, independent of the page.
Search WWH ::




Custom Search