|
![]() |
![]()
JSP groups pages into applications which share common state. A bulletin board application groups pages for article reading, group listing, user registration, and new article posting into a single application. Applications can keep track of user sessions, giving the users the illusion of a single application out of disjointed pages.
The .application directory organizes an application. It defines an application docroot by its presense. All files and directories in the docroot are part of the same application.
ScriptsJSP applications can group common functions and classes into script files, organizing and simplifying the application. The individual pages can then import the common scripts to use them. JSP pages can focus on HTML presentation and the script libraries can concentrate on the content.As described in the import documentation, Resin searches for imported scripts along a SCRIPTPATH. For JSP pages, the SCRIPTPATH looks in the application script directory first, then in the global libraries.
DataThe data subdirectory of .application can contain any data the JSP application needs to store. It could contain persistent state for a counter, to the entire article tree for a complicated discussion server.The File object in a JSP script uses .application/data as its current directory. TagsJSP 1.0 provides an extensible tag architecture, allowing applications to design their own active tags. The tag handlers are Java classes extending theChunkHandler interface. When the JSP parser encounters a new
tag, it looks in tags for a matching class.
The global.jsa file contains common declarations, application and session bean declarations, and event handlers. Its structure resembles to a JSP file, except that it never creates content. Session and application beans must be declared in a global.jsa jsp:usebean directive. Only page beans may be declared in a *.jsp file. The application beans will be instantiated when the first page of the application is accessed and will persist until the server shuts down. Error pages global to the entire application may be declared in the global.jsa file. Local error page declarations override the global declarations. The language declared in the global.jsa file is local to the global file. It only declares the language for the declaration section and the event handlers. Event HandlersApplications can declare event handlers to execute when an application starts or stops and when a session starts and stops. The event handlers can initialize state, read data from storage, and store the final state when the server shuts down.Applications start on the first page access. The application event handlers jsp:application:onStart and jsp:application:onEnd can use the application object. Sessions start when a page accesses session state or when a session bean is created. Sessions end when the server times them out, when the application ends, or when they are invalidated. The session event handlers jsp:session:onStart and jsp:session:onEnd can use the session and application objects.
Session variables let applications keep track of the user as she moves through the site. Any e-commerce site needs this capability to keep track of the user's purchases. JSP sessions start when the page accesses the session variable. If a page never uses sessions, the jsp:session:onStart code will not execute and the web server will not send the client any cookies. Sessions end when the session times out, when the session is invalidated, or when the application ends. Resin locks the session variable before executing the page. So JSP applications don't need to worry about synchronizing the session variable.
Java Beans get first class treatment in JSP 1.0. Beans can be created for a page, across a session, or for the entire application. The .application/beans subdirectory can contain application beans used by jsp:usebean. These are simply Java classes implementing the bitmechanic work of an application. For example, a shopping cart application may have a set of Java classes that perform the security necessary for credit card processing. The application can put those classes in the beans directory and access them from the JSP page. Beans can be created with different lifetimes.
Accessing BeansEach bean is defined with a jsp:usebean directive. Page beans are defined in the JSP page. Session and application beans are defined in the global.jsa file.JSP assigns the created bean object to the JavaScript variable named by jsp:usebean. In addition, the created beans are stored in JSP variables: page
beans are stored in
|