Using Beans


Directives

The Resin server and the JSP specification define a large number of JSP directives that you can use to change the preferences for a given JSP page. Table 3.3 lists those supported by Resin. Most of the options are self-explanatory, but we cover some of the more important ones here.

Table 3.3: JSP Directives Supported by Resin

DIRECTIVE

DESCRIPTION

<%@ include file="path" %>

The include directive combines the specified file with the current page before the JSP translation/conversion takes place.

<%@ page autoFlush="true" %>

The autoFlush directive tells Resin to automatically flush the output buffer when it gets full.

<%@ page buffer=sizekb %>

The buffer directive tells Resin the size of the output buffer used to generate the response from the JSP or servlet page.

<%@ page contentType="description" %>

The contentType directive sets the MIME type of the page.

<%@ page errorPage="path" %>

The errorPage directive defines a page to display if an error occurs in the JSP page.

<%@ page extends="Java class" %>

The extends directive specifies the parent class of the servlet produced from the translation of the JSP page.

< /o@ page import="package" %>

The import directive specifies the packages used in the page.

<%@ page info="description" %>

The description directive specifies a description for the page.

< /o@ page isErrorPage="true" %>

The isErrorPage directive specifies that the page is an exception page.

<%@ page isThreadSafe="true" %>

The isThreadSafe directive tells Resin whether or not the page can be accessed concurrently. The default is true, which means Resin assumes you have synchronized any sensitive data accesses. A value of false causes the page to be accessed sequentially and degrades performance.

<%@ page language="lang" %>

The language directive lets Resin know what language is being used in the script code.

<%@ page session="true" %>

The session directive instructs Resin to associate a Session object with the page. The default is true. If the page doesn't need to be part of a session set, the value is false and resources will be saved.

<%@ taglib prefix="x" uri="foo" %>

The taglib directive specifies taglibs for the current page.

Imports

In most of the examples to this port, we've included the entire package path for the Java classes that we wanted to use. It would certainly be more helpful to have a mechanism that allows us to list the imports just like we do when writing a traditional Java application. You can use the import directive for this purpose. For example:

 <%@ page import = "java.util.*" %> <HTML> <BODY> <%     Date localTime = new Date();     System.out.println("Pulled the correct date"); %> Hello World! <BR> The time is <%= localTime %> </BODY> <HTML> 

Using the import directive means you don't need to use the java.util.Date declaration—you simply use Date. If you have multiple packages, separate them using a comma. For example, you can use the following statement to import both the java.util and javax.sql packages:

 <%@ page import = "java.util.*, javax.sql.*" %> 

Sessions

By default, all requests for a JSP page result in the creation of a Session object. Using cookies or URL encoding, you can track the session. However, if you don't need sessions or have pages that should generate a Session object, you can use the session directive instead. For example:

 <%@ page session="false" %> 

This directive prevents a Session object from being created.

Error Pages

All JSP pages contain a certain level of Java code to help in the dynamic nature of the page. The Java code has the potential to produce errors when executed. When an error occurs in the page, we don't want the server to issue its own error; instead, we want to display an error page (that uses the look and feel of the site) to provide the user with helpful information. You can assign an error page to individual pages by using the errorPage directive. For example:

 <%@ page errorPage="dberror.jsp" %> 

This directive defines the dberror.jsp page, which will be used in the event an error occurs on the current page.

Includes

During development of JSP pages, you will likely come across pages where information has to be repeated. Instead of just using the cut-and-paste method, use the include directive. For example, if you have a header for each page, you can use a directive like this:

 <%@ include file="header.jsp" %> 




Mastering Resin
Mastering Resin
ISBN: 0471431036
EAN: 2147483647
Year: 2002
Pages: 180

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net