I was wondering if there was anyway of using JSP in <c:if>
statement.
E.g.
<c:if test="${ param.variable1 == 'Add' <% JSP variable clause %>}">
So I want my JSP variable to checked against as well.
Any suggestions? I have tried ignorantly just sticking in the clause, obviously it did not work.
Thanks
print("Result is "+res); %>The Result is <%=a+b%>An Expression tag is used to evaluate an expression and assigns its value but scriptlet tag is for simply java code that may be any statements like expression,display statements etc.
Scriptlets can only be included in a JSP page (typically configured to be *. jsp). The statement as presented, if processed by the JSP compiler, would result in myVar being equal to '' as the scriptlet format you are using <% ... %> executes Java code between the tags, but does not return a result.
A scriptlet is a piece of software code that is used by a native Web page scripting language to perform a specific function or process. Scriptlets are primarily implemented in JavaServer Pages (JSP) and include variables, expressions or statements that are used only when requested by a certain client or process.
So you want to evaluate a scriptlet variable in EL? Store it as a request attribute.
<%
String var = "some";
request.setAttribute("var", var);
%>
<c:if test="${param.variable1 == 'Add' && var == '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="var" value="some" scope="request" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With