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?
Scripts are raw java embedded in the page code, and if you declare variables in your scripts, then they become local variables embedded in the page.
In contrast, JSTL works entirely with scoped attributes, either at
page,requestorsessionscope. You need to rework your scriptlet to fishtestout as an attribute:If you look at the docs for
<c:set>, you’ll see you can specifyscopeaspage,requestorsession, and it defaults topage.Better yet, don’t use scriptlets at all: they make the baby jesus cry.