How to evaluate a scriptlet variable in EL?

感情迁移 提交于 2019-11-26 05:38:40

问题


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


回答1:


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" />

See also:

  • Our EL wiki page
  • Difference between <%= foo %> and ${ foo }
  • Use EL ${XY} directly in scriptlet <% XY %>
  • What are implicit objects? What does it mean?


来源:https://stackoverflow.com/questions/5965812/how-to-evaluate-a-scriptlet-variable-in-el

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!