0

While writing a page in JSP, we can either use the implicit variables

application,request,session

or use the pageContext variable along with pageContext.Application_SCOPE etc.

Why should we use pageContext in place of the implicit variables, and what are the advantages/disadvantages for using either of them.

ex:- Why use

pageContext.setAttribute("Key","Value",pageContext.REQUEST_SCOPE)

vs

request.setAtrribute("Key","Value")

Edit:

Nathan Hughes proposed that my question is a duplicate. But the question he , provided a link to elaborates pageContext with respect to ExpessionLanguage while my question actually relates to pageContext with respect to Scriptlets.

Expression Language - ${pageContext.session} - This returns a Session object. API as given by Eclipse

Scriplets - <% pageContext.SESSION %> - This returns a String. API as given by Eclipse

The pageContext variable has different behavior in the above two Contexts. So , now that i have established how my question differs, can anyone answer my original question?

Shaurya Chaudhuri
  • 3,772
  • 6
  • 28
  • 58

0 Answers0