Reputation:
I found out the code to pass a java variable to jstl like this :-
<%
String str = "abc";
pageContext.setAttribute("str", str);
%>
and to get that value in jstl tags we will have to use the code like this :-
<c:out value="${str}"/>
My main question is that, if there any other method to do so to pass on the values, from java to jstl?
Upvotes: 0
Views: 5112
Reputation: 240890
it looks for pageContext, request attributes, session attributes, application context for variable resolution, so you can put the value in any of this
in this example you are putting it in pageContext
From our EL wiki
${str}
does basically the same as the following in "raw" scriptlet code (the below example is for simplicity, in reality the reflection API is used to obtain the methods and invoke them):
where PageContext#findAttribute()
scans the attributes of respectively the PageContext
(page scope), HttpServletRequest
(request scope), HttpSession
(session scope) and ServletContext
(application scope) until the first non-null value is found. Please note that it thus doesn't print "null" when the value is null nor throws a NullPointerException
unlike as when using scriptlets. In other words, EL is null-safe.
Upvotes: 2
Reputation: 49372
You are not passing values to JSTL , you are setting scoped attributes . You can set attributes to request
,session
and context
or you can pass request
parameters to the JSP.
Upvotes: 0