Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

jsp - How to evaluate a scriptlet variable in EL?

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

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...