Reputation: 87
I want to be able to send an alert if a query string exists, but I dont need to know the value it returns, just that it exists.
I tried this, but it doesnt work:
<%
request.setAttribute("appInfo", request.getParameter("appInfo"));
%>
<c:if test="${appInfo}">
<script>
alert("${appInfo}");
</script>
</c:if>
I also tried this (with the url being ?appInfo=88) and it worked.
<%
request.setAttribute("appInfo", request.getParameter("appInfo"));
%>
<c:if test="${appInfo == 88}">
<script>
alert("${appInfo}");
</script>
</c:if>
I dont understand why solution 2 works but 1 doesnt, any ideas?
Upvotes: 0
Views: 1411
Reputation: 51052
c:if
doesn't work like a Javascript if, where non-null values will be regarded as "truthy". For c:if
you need a result that actually is true or false. You can do
<c:if test="${appInfo != null}">
to check if the value is there.
Upvotes: 1