I have something like in my JSP page :
<% if(id!=null) { %>
<input type="hidden" name="id" value="<%= id %>" />
<%
}
%>
When I want to edit a user id should be non null, then I want that input in my HTML.
However, when I want to add a user id should be null, and so I don’t what that input.
It works great with that code. But I would like to use JSTL i tried using c:if and c:when :
<c:choose>
<c:when test="${id != null }">
<input type="hidden" name="id" value="<%=id%>" />
</c:when>
<c:otherwise>
<br/>
</c:otherwise>
</c:choose>
The problem is that this code displays <br /> when id is null or non null (add and edit) … And I don’t see why it doesn’t work.
Thanks for your help,
S
The problem is that your variable id is not in a scope which jstl can reach.
You need to do:
Also, it’s better to test against empty:
And lastly, you should use jstl when outputting the value of id: