Reputation: 5963
In JSP pages I am using a custom JSTL function, which has the request
object as one of the inputs.
Currently I am using the following way of accesing it in my JSP.
<c:if test="${custom:isVisitorFromNorthAmerica(request)}">
...
</c:if>
The tag function definition is as follows,
<function>
<name>isVisitorFromNorthAmerica</name>
<function-class>com.x.y.JspELFunctions</function-class>
<function-signature>
java.lang.Boolean isVisitorFromNorthAmerica(javax.servlet.http.HttpServletRequest)
</function-signature>
</function>
Inside the function definition of custom#isVisitorFromNorthAmerica
the request object is null. I am not sure how to access the request
object then, without resorting to scriptlets.
I made sure that the request
object being sent to the custom tag is not null, because I added a scriptlet just before the custom function invocation & it is set properly.
Upvotes: 1
Views: 678
Reputation: 5963
I found the answer. I need to access it using pageContext
. So instead of calling it like so,
<c:if test="${custom:isVisitorFromNorthAmerica(request)}">
I need to call it like so,
<c:if test="${custom:isVisitorFromNorthAmerica(pageContext.request)}">
Upvotes: 4