IPOWERWEB.com

 Affordable, reliable
web hosting solutions

Call IPOWERWEB Today at 1-888-511-HOST Chat with an IPOWERWEB representative LIVE!
24/7x365 service - Live Technical Support

Domain Name Registration
web hosting services
cheap web hosting
IPOWERWEB help section
contact IPOWERWEB
testimonials for best hosting
affordable web hosting
IPOWERWEB web hosting
IPOWERWEB accolades
best domain prices


Web Hosting Money Back Guarantee
home build profit promote manage


Introducing Java Server Pages

Home > Build > Backend > Java Server Pages

Chapter 7- Introducing Java Server Pages
Page 3 of 4

(1) (2) (3) (4)

JSP Directives

A JSP directive is a statement that gives the JSP engine information for the page that follows. The general syntax of a JSP directive is <%@ directive { attribute="value" } %>, where the directive may have a number of (optional) attributes. Each directive has an optional XML equivalent, but these are intended for future JSP tools, so we won't consider them here.

Possible directives in JSP 1.0 are:  

  • Page - information for that page
  • Include - files to be included verbatim
  • Taglib - the URI for a library of tags that you'll use in the page (not implemented at the time of writing)

  As is to be expected, the page directive has many possible attributes. Specifying these is optional, as the mandatory ones have default values.  

Attribute and possible
values

Description

language="Java" The language variable tells the server what language will be used in the file. Java is the only supported syntax for a JSP in the current specification. Support for other scripting languages is available at http://www.plenix.org/polyjsp and http://www.caucho.com (JavaScript).
extends="package.class" The extends variable defines the parent class of the generated servlet. It isn't normally necessary to use anything other than the provided base classes.
import="package.*,
package.class"
The import variable is similar to the first section of any Java program. As such, it should always be placed at the top of the JSP file. The value of the import variable should be a comma-separated list of the packages and classes that you wish to import.
session="true|false" By default, the session variable is true, meaning that session data is available to a page.
buffer="none|8kb|sizekb" Determines if the output stream is buffered. By default it is set to 8kb. Use with autoFlush
autoFlush="true|false" If set to true, flushes the output buffer when it's full, rather than raising an exception.

Attribute and possible values

Description

isThreadSafe="true|false" By default this is set true, signaling to the JSP engine that that multiple client requests can be dealt with at once. It's the JSP author's job to synchronize shared state, so that the page really is thread safe. If isThreadSafe is set to false, the single thread model will be used, controlling client access to the page. This doesn't let you off the hook, however, as servers may, at their discretion, have multiple instances of the page running to deal with the client request load. And there's no guarantee that consecutive requests from the same client will be directed to the same instance of JSP page. Any resources or state that are shared between page requests must therefore be synchronized.
info="text" Information on the page that can be accessed through the page's Servlet.getServletInfo() method.
errorPage="pathToErrorPage" Gives the relative path to the JSP page that will handle unhandled exceptions. That JSP page will have isErrorPage set to true
isErrorPage="true|false" Marks the page as an error page. We'll see this in action later.
contentType="text/html; charset=ISO-8859-1" The mime type and character set of the JSP and the final page. This information must come early in the file, before any non-latin-1 characters appear in the file.

In the JSWDK-1.0-ea1 release there's a bug - the import statement needs to be imports to satisfy the JSP engine. We'll see more of the include directive in a later example.

JSP Declarations

A JSP declaration can be thought of as the definition of class-level variables and methods that are to be used throughout the page. To define a declarative block, begin the block of code with <%! declaration>.

<%! String var1 = "x";

    int count = 0;

 private void incrementCount()

{

       count++;

}

%>

Note that you put semicolons after each variable declaration, just as if you were writing it in a class.  

This is how you would define the optional jspInit() and jspDestroy() methods that we mentioned earlier.

 
home | products | about us | help center | testimonials | press room | contact us
affiliates | careers | domain names | web hosting | site map

Copyright © 1999-2007 IPOWER, Inc. Read our Terms and Conditions. All rights reserved.