How to avoid character in EL with JSTL tag?
I have this piece of JSP code:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:choose>
<c:when test="${var1.properties[\"Item Type\"] eq \"Animal Part\"}">
<c:set var="cssClassName" value="animalpart" />
</c:when>
<c:otherwise>
<c:set var="cssClassName" value="" />
</c:otherwise>
</c:choose>
JSP could not be compiled by the server. However, if I remove the ββ symbol from the βAnimal Partβ, it will compile. I tried to escape from it with the "\" character, but it still gives me an error.
Any suggestion / help is appreciated. I tried to avoid using a script if possible.
Thanks.
EDIT : I managed to get it working (after posting on StackOverflow), posted as one of the solutions in this question. I tried another solution published before (Vincent and Eddie), however, unfortunately, it does not work in my environment, although I believe that they can work in the response environment. Thanks.
, :
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="itemType" value="${var1.properties[\"Item Type\"]}" />
<c:set var="item_animalpart" value="Animal Part" />
<c:set var="item_treepart" value="Tree Part" />
<c:choose>
<c:when test="${itemType eq name_item_animalpart}">
<c:set var="cssClassName" value="animalpart" />
</c:when>
<c:when test="${itemType eq name_item_treepart}">
<c:set var="cssClassName" value="treepart" />
</c:when>
<c:otherwise>
<c:set var="cssClassName" value="" />
</c:otherwise>
</c:choose>