Monday, February 18, 2008

Javabeans for JSP ans Scopes

special type of class that has a number of methods.
JSP page can call these methods..
Javabean could be used in another JSP page (promoting reuse).

__To use a Javabean in a JSP page use the following syntax:

< id = " ...." scope = "application" class = "com...">

** scopes:

page - valid until page completes.

request - bean instance lasts for the client request

session - bean lasts for the client session.

application - bean instance created and lasts until application ends.


more about scopes.....



Application scope

Application scope is the broadest scope and should only be used when necessary. You can

create objects bound at application level in JSPs that are not session-aware. You can also

use application-bound objects to share data among different sessions of the same

application. When you no longer need objects bound to an application, you should explicitly

remove them to free up memory resources.



Session scope

In my experience, session scope is more commonly used than application scope. Session scope

allows you to create and bind objects to a SESSION. You must create objects bound to the

session in session-aware JSPs and make them available to all JSPs and servlets in the same

session. Session scope is often used for managing security credentials and for managing

state among multiple pages. As with application scope,

objects bound to session scope should be explicitly removed when no longer needed.



Request scope

I use request scope most often for binding created objects. Objects created and bound to

request scope are available to pages in that same request. These objects are automatically

released from memory when request processing completes. This is advantageous because

explicit cleanup is not required and there is less risk of burdening the system with

needless memory consumption.



Page scope

You should use page scope for objects created only for the current page. Like request scope,

the page scope does not require explicit removal of created and bound objects. I rarely use

page scope in my JSP applications, but it is the action's default scope.

No comments: