Programmable JSP elements are divided into five categories: directives, scripting elements, declarations, expressions, and actions.
Let s take a look at the elements in the first category. JSP Directives JSP directives are JSP elements that send messages to the JSP container. Directives affect the overall structure of the servlet generated from the JSP page.
JSP directives do not produce any output to the generated document. The general format of a JSP directive is:
<%@ directiveType attributelist %>
The first word, directiveType, is one of three values: page, include, and taglib.
The second word, attributelist, is one or more name-value pairs; the name part is the name of the attribute relevant to the directive type and the value is a quoted string relevant to the attribute name.
If the directive contains more than one name-value pair, the distinct pairs are delimited by one or more spaces, such as the following JSP directive:
<%@ page buffer="8k" language="java" %>
The page directive
The page directive enables you to communicate a number of important attributes to the generated servlet. Using the page directive, you can direct the servlet to import classes, define a general error reporting page, or set a content type. The page directive follows the general form shown below:
<%@ page attributelist %>
You can code one or more page directives in your JSP page. However, with one exception, take care to ensure that you code only one name-value pair per page. The exception is that you may code more than one import attribute, the use of which is explained shortly. You may code page directives anywhere in your JSP page. By convention, page directives are coded at the top of the JSP page. JSP also permits a coding style that follows XML syntax rules. The following is an example of a page directive coded with the XML style:
<jsp:directive.page buffer="8k" />
The preceding page directive is the same as the example shown here:
<%@ page buffer="8k" %>
The buffer attribute
The buffer attribute specifies buffering characteristics for the server output response object. You d want a buffer for efficiency because buffered output is usually quicker than unbuffered output. Writing to the browser requires resources.
The server sends buffered output in large blocks a few times, which requires less resources than sending unbuffered output in small blocks more often. You may code a value of "none" to specify no buffering so that all servlet output is immediately directed to the response object. You may code a maximum buffer size in kilobytes, which directs the servlet to write to the buffer before writing to the response object.
Here are a few coding examples: To direct the servlet to write output directly to the response output object, use the following:
<%@ page buffer="none" %>
Use the following to direct the servlet to write output to a buffer of size not less than 8 kilobytes:
<%@ page buffer="8kb" %>
We have plenty of other tutorials on our wiki pages. Check out our Java hosting wiki.