When we can access all the implicit variables in JSP, why do we have pageContext ?
My assumption is the following: if we use EL expressions or JSTL, to access or set the attributes we need pageContext. Let me know whether I am right.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You need it to access non-implicit variables. Does it now make sense?
Update: Sometimes would just like to access the getter methods of
HttpServletRequestandHttpSessiondirectly. In standard JSP, both are only available by${pageContext}. Here are some real world use examples:Refreshing page when session times out:
Passing session ID to an Applet (so that it can communicate with servlet in the same session):
Displaying some message only on first request of a session:
note that
newhas special treatment because it’s a reserved keyword in EL, at least, since EL 2.2Displaying user IP:
Your IP is: ${pageContext.request.remoteAddr}Making links domain-relative without hardcoding current context path:
Dynamically defining the
<base>tag (with a bit help of JSTL functions taglib):Etcetera. Peek around in the aforelinked
HttpServletRequestandHttpSessionjavadoc to learn about all those getter methods. Some of them may be useful in JSP/EL as well.