Monday, December 22, 2014

JSP page vs PageContext

page

class: java.lang.Object
page represents the current servlet/jsp object.
page represents 'this'.

pageContext

class: javax.servlet.jsp.PageContext
Use to foward/redirect to particular url.
Use to include particular url.
Use to store/retrieve page level values.
It provides the following list of objects 

ServletRequest
ServletResponse
ServletContext
ServletConfig
HttpSession

application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
request = pageContext.getRequest();
response = pageContext.getResponse();
out = pageContext.getOut(); 


It provides following list of constants

public static final String APPLICATION
public static final int APPLICATION_SCOPE
public static final String CONFIG
public static final String EXCEPTION
public static final String OUT
public static final String PAGE
public static final int PAGE_SCOPE
public static final String PAGECONTEXT
public static final String REQUEST
public static final int REQUEST_SCOPE
public static final String RESPONSE
public static final String SESSION
public static final int SESSION_SCOPE

Object obj = pageContext.getAttribute("BeginnersBook", PageContext. REQUEST_CONTEXT);
Object obj = pageContext.getAttribute("BeginnersBook", PageContext. PAGE_CONTEXT);
Object obj = pageContext.getAttribute("BeginnersBook", PageContext. APPLICATION_CONTEXT);
If it finds the attribute it would assign it to Object obj else it would return Null.

pageContext.setAttribute(“userName”, “RAJ”, PageContext.APPLICATION_CONTEXT);
pageContext.removeAttribute(“userName”, PageContext.APPLICATION_CONTEXT);

Keep Visiting :)
Give your valuable Comment

No comments:

Post a Comment

Scrum and Scrum master

Scrum  Scrum is a framework which helps a team to work together.  It is like a rugby team (the scrum name comes from rugby game). Scrum enco...