Nice book written by Damon Hougland and Aaron Tavistock.
Few important quotations i wanted to share from next two chapters ( 3-4).
1) Objects with page scope are accessible only as a part of the page that they are created in. References to objects with a scope of page are released after the response is sent back to the client from the JSP page or the request is forwarded somewhere else. References to objects with page scope are stored in the pageContext object.
Objects with request scope are accessible from pages processing the same request where they were created. When the request is processed any object with a scope of request will be released. This is similar to the page scope, except that the object will still be accessible if the request object is passed to another JSP page. References to objects with request scope are stored in the request object.
Objects with session scope are accessible from pages processing requests that are in the same session as the one in which they were created. Before an object can be created with a session of scope the JSP page must be declared sessionaware (in the page directive). All references to an object with a scope of session are released after the associated session ends. References to objects with session scope are stored in the session object.
Objects with application scope are accessible from pages processing requests that are in the same application as they one in which they were created. All objects of application scope will be released when the JSP page is ended by the ServletContext, usually through the server shutdown, the page timeout, or a call to the jspDestroy () method. References to objects with application scope are stored in the application object.
2)
The setProperty action sets the properties of a Bean. The Bean must have been previously defined before this action.
3)
The useBean action finds or creates an instance of an object. It also associates this object with an implicit object specified by the scope attribute (page, request, session,and application). It identifies this new object with the value of the id attribute. It also creates a new scripting variable under the name of the id attribute that references the object.
4) The Page Directive
The page directive allows several different page-specific attributes to be set. It directly influences how the Java program created from the JSP page is formed. The JSP page, including any JSP pages included with the include directive, can have any number of page directives. There must not be more than one instance of each attribute/value pair with the single exception of the import attribute. Multiple import attributes pairs are cumulative.
Page directives always begin with the standard JSP open tag followed by an @ symbol and the keyword page. Here are a couple of example page directives:
5) Multithreading and Persistence
JSP inherits multithreading and persistence from Java Servlets. Being persistent allows objects to be instantiated when the Servlet is first created, so the physical memory footprint of the JSP Servlet remains fairly constant between requests.Variables can be created in persistent space to allow the Servlet to perform caching,session tracking, and other functions not normally available in a stateless environment.
The JSP author is insulated from many of the issues involved with threaded programming. The JSP engine handles most of the work involved in creating, destroying, and managing threads. This frees the JSP author from many of the burdens of multithreaded programming. However, the JSP author needs to be aware of several aspects of multithreaded programming that affect JSP pages.
Threads can inadvertently cause harm to other threads. In these situations the JSP programmer needs to understand when and how to protect their pages from threading.
6) Persistence
Because the Servlet is created once and remains running as a constant instance, it allows persistent variables and objects to be created. Persistent variables and objects are shared between all threads of a single Servlet. Changes to these persistent objects are reflected in all threads.
From the perspective of the JSP author, all objects and variables created within declaration tags (<%!...%>) are persistent. Variables and objects created within a thread will not be persistent. Code inside of a scriptlet, expression, and action tags will be run within the new request thread and therefore will not create persistent variables or objects.
Having persistent objects allows the author to keep track of data between page requests. This allows in-memory objects to be used for caching, counters, session data, database connection pooling, and many other useful tasks.
About the Authors
DAMON HOUGLAND is a Program Manager and Technical Architect for eFORCE, Inc., where he designs and develops Java enterprise applications. Previously Damon led the Web Application Infrastructure team at Lawrence Berkeley National Laboratory, which specialized in reporting scientific data through web-enabled databases and applications. He has worked as a software developer and technical manager over the last nine years.
AARON TAVISTOCK has over 10 years of experience with UNIX systems and application development. He has used his extensive knowledge of Java, JSP, and taglibs to create a leading edge web application compiler. Aaron is currently the Web Compiler Architect for Snapshop.com, Inc., a provider of B2B2C (business-to-business-to-consumer) web applications.
No comments:
Post a Comment