JSP PageContext Implicit Object

Introduction:
1.    pageContext variable is of type javax.servlet.jsp.PageContext.
2.     The PageContext class is the abstract class and JSP engine vendor provides its concrete subclass.
3.     We can use pageContext implicit object for the following purpose
·       To get all other jsp implicit objects.
·        Provide method to get and set attributes in different scopes.
·        Provide convenience methods for transferring request to other resources in web application.
PageContext.forward(other.jsp”);
1.     Getting Jsp implicit objects from pageContext
PageContext class defines the following methods for this.     
·       request           à      getRequest ( )
·        response         à      getResponse ( )
·        config             à      getServletConfig ( )
·        application     à      getServletContext ( )
·        session           à       getSession ( )
·        out                 à       getOut ()
·        page               à       getPage ( )
·        exception       à       getException ( ) 
These methods are not useful within the Jsp because all implicit objects are available in every Jsp.     But these methods are useful outside the Jsp mostly in custom tag handlers.
2.Attribute Management in any scope
In JSP, pageContext is an implicit object of type PageContext class. The pageContext
Object can be used to set, get or remove attribute from one of the following scopes
1.    Page
2.     Request
3.     Session
4.     application
In JSP, page scope is the default scope.
Example:
pageContext.setAttribute("user","myjavahub",PageContext.SESSION_SCOPE);
3.Request Dispatching by pageContext
We can perform Request Dispatching by using pageContext.
For this PageContext class defines the following methods.
1.    public void forward (String  target)
2.     public void include (String   target)

Thanks For Making This Possible! Kindly Bookmark and Share it.

Technorati Digg This Stumble Stumble Facebook Twitter

No comments:

Post a Comment