Directive Tag

A directive tag is a tag embedded in the JSP page that can be used by the developer to issue directives to the JSP compiler. The directive tag affects the way the JSP file is compiled into a servlet by the JSP compiler. Directive tags must always be present at the beginning of the JSP.

Structure of the Directive Tag

JSP directive tags can be written in two ways:

 <%@ tagname attributename=attributevalue attributename=attributevalue %>  

or

 <jsp: directive.tagname attributename=attributevalue          attributename=attributevalue /> 

The second example is the XML representation of the JSP directive tag. A directive tag consists of a tag name and its attributes and attribute values.

Available Directive Tags

There are three directive tags available in the JSP 1.2 specification.

The page Tag

The page tag directive enables a developer to affect the way the JSP is compiled by the JSP compiler. Here is an example of the page tag:

 <%@ page attribute1name="attribute1value" attribute2name="attribute2value" ...>  

or

 <jsp:directive.page attribute1name="attribute1value"          attribute2name="attribute2value" .../> 

The import attribute of the page tag enables the compiler to use the package qualifiers of any Java classes referenced in the embedded Java code. The import attribute acts like the import statement in a normal Java file:

 <%@ page import="com.samspublishing.learnweblogic7.*">  

or

 <jsp:directive.page import="com.samspublishing.learnweblogic7.* " />  

The value of the import attribute, com.samspublishing.learnweblogic7.*, enables the JSP compiler to compile all class references of the com.samspublishing.learnweblogic7 package that are contained within the JSP.

Since you are dealing with Web applications, any response sent to the browser by the JSP's compiled servlet is identified using a MIME type. By default, the MIME type used for sending a response is "text/html". This enables the browser to interpret all data sent to the browser from the JSP's compiled servlet as HTML, which is then rendered by the browser accordingly. In case your JSP sends a different type of data, say, a GIF image, you can modify the content type by setting a new MIME type, such as "image/gif":

 <%@ page contentType="image/gif">  

or

 <jsp:directive.page contentType="image/gif" />  

The contentType attribute has the value "image/gif", which enables the browser to read all the response data from the JSP's compiled servlet and interpret it as a GIF image, which will be rendered by the browser.

The isThreadSafe attribute is not normally changed by a developer. The default value of the isThreadSafe attribute is true. This signifies that the JSP's compiled servlet will be loaded as a multithreaded servlet with none of its variables affected by concurrent use:

 <%@ page isThreadSafe="true">  

or

 <jsp:directive.page isThreadSafe="true" />  

The default true value identifies that a single instance of the JSP's compiled servlet is used for processing. Multiple requests are processed by executing the servlet in different threads. All variables of the servlet are signified by this attribute value to be thread-safe.

The include Tag

With the include tag directive, you can include files from the file system within the JSP. The contents of the included files and the contents of the JSP are combined before the JSP is compiled:

 <%@ include file="url" >  

or

 <jsp:directive.include file="url"/>  

The file attribute is the only attribute available for the include tag. The file attribute is used to specify the URL of the filename to be included within the JSP. The value of the file attribute is the filename of the file to be included:

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

or

 <jsp:directive.include file="myContentsFile.jsp" />  

The value of the file attribute, myConstantsFile.jsp, instructs the JSP engine to include the myConstantsFile.jsp file within the current JSP file. The contents of the two files are combined before the JSP compiler compiles the servlet.

The taglib Tag

The taglib tag is a new tag introduced in the JSP 1.1 specification. The taglib directive enables the JSP compiler to load the library classes of any custom tags embedded in the JSP. Custom-tag library development, including the use of the taglib tag, will be explained on Day 6. There is no XML equivalent for the taglib directive:

 <%@ taglib uri="taglibraryurl" prefix="tagprefix">  

The uri attribute identifies the location of the .tld tag library of the custom tags used in the JSP. The JSP compiler refers to the tag library from the location specified as the value for the uri tag:

 <%@ taglib uri="/myapp/mytaglibrary.tld" prefix="learnweblogic7">  

The tag library mytaglibrary.tld is assigned as the value of the uri attribute for the taglib directive tag. The Java classes for the custom tag library will be loaded from the specified uri, /myapp/mytaglibrary.tld.

The prefix attribute is used to define the prefix name for the tags used in the custom tag library. The prefix attribute cannot have a blank value:

 <%@ taglib uri="/myapp/mytaglibrary.tld" prefix="learnweblogic7">  <learnweblogic7> ... </learnweblogic7> 

The prefix attribute is given the value learnweblogic7, which will be used in the JSP as a custom tag.



Sams Teach Yourself BEA WebLogic Server 7. 0 in 21 Days
Sams Teach Yourself BEA WebLogic Server 7.0 in 21 Days
ISBN: 0672324334
EAN: 2147483647
Year: 2002
Pages: 339

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