The following code causes an error:
<c:set var="test" value="test1"/>
<%
String resp = "abc";
resp = resp + test;
pageContext.setAttribute("resp", resp);
%>
<c:out value="${resp}"/>
The error says
"error a line 4: unknown symbol 'test'".
How do I pass test
from the JSTL code to the JSP scriptlet?
@skaffman nailed it down. They live each in its own context. However, I wouldn't consider using scriptlets as the solution. You'd like to avoid them. If all you want is to concatenate strings in EL and you discovered that the +
operator fails for strings in EL (which is correct), then just do:
<c:out value="abc${test}" />
Or if abc
is to obtained from another scoped variable named ${resp}
, then do:
<c:out value="${resp}${test}" />
Source: Stackoverflow.com