PageContext findAttribute vs getAttribute methods - Java @ Desk

Saturday, May 10, 2014

PageContext findAttribute vs getAttribute methods

PageContext findAttribute vs getAttribute methods

In PageContext class, there are three methods:
1) findAttribute(java.lang.String name)
2) getAttribute (java.lang.String name)
3) getAttribute (java.lang.String name, int Scope)

There is a slight difference among the three as mentioned below:
findAttribute searches for the named attribute in all the 4 scopes i.e. page, request, session (if valid), and application scope(s) in order and returns the value associated or null.

getAttribute return the object associated with the name in the page scope only or null if not found.

getAttribute(java.lang.String name, int scope) return the object associated with the name in the specified scope or null if not found.






No comments:

Post a Comment