So you want to evaluate a scriptlet variable in EL? Store it as a request attribute. The below example will make it available as ${foo}
.
<%
String foo = "some";
request.setAttribute("foo", foo);
%>
<c:if test="${param.variable1 == 'Add' && foo == 'some'}">
However, this makes no sense. You should avoid scriptlets altogether and use JSTL/EL to prepare this variable. So if you make the functional requirement more clear, e.g. "How do I do this (insert scriptlet code snippet) using JSTL/EL?", then we'll be able to suggest the right approach.
For example, you could use <c:set>
to set a variable in EL scope.
<c:set var="foo" value="some" scope="request" />
Or if the JSP is forwarded by a servlet, then use request.setAttribute()
over there right away.
String foo = "some";
request.setAttribute("foo", foo);
request.getRequestDispatcher("/WEB-INF/your.jsp").forward(request, response);
This will then be available as ${foo}
the same way.
See also:
pageScope.var
. Sure enough, it didn't work. Weirdly, when simply usingvar
in the EL it does work without having to place the variable in the scriptlet code in request scope. What am I missing? – Aciculate