2009-06-15 5 views
5

이 JSP 코드 스 니펫이 있습니다.JSTL 태그로 EL에서 문자를 빠져 나오려면?

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 

<c:choose> 
    <c:when test="${var1.properties[\"Item Type\"] eq \"Animal's Part\"}"> 
    <c:set var="cssClassName" value="animalpart" /> 
    </c:when> 
    <c:otherwise> 
    <c:set var="cssClassName" value="" /> 
    </c:otherwise> 
</c:choose> 

JSP를 서버에서 컴파일 할 수 없습니다. 그러나 "동물의 부분"에서 문자 " '"를 제거하면 편집 할 수 있습니다. 나는 "\"문자를 사용하여 그것을 벗어나려고했지만 여전히 오류가 발생합니다.

제안/도움을 주시면 감사하겠습니다. 가능한 경우 스크립틀릿 사용을 피하려고했습니다.

고마워.

EDIT :이 문제의 해결책 중 하나로 게시 된 StackOverflow에 게시 한 후 작동하도록했습니다. 나는 다른 솔루션을 (Vincent와 Eddie에 의해) 게시했지만 불행히도 아무도 내 환경에서 작동하지 않는다. 응답 환경에서 작동 할 수도 있다고 생각한다. 감사.

+0

Eddie 's/Vincent의 솔루션이 작동하지 않는 환경은 무엇입니까? – hop

답변

3

:

<c:out value="${formulario}" escapeXml="false" /> 
+0

** item_animalpart ** 및 ** item_treepart **는 중복 정의입니다. – gavenkoa

6

예를 들어이

<c:when test='${var1.properties["Item Type"] eq "Animal\'s Part"}'> 
0

사용 escapeXml = "false"를 을 시도하십시오이 작동 솔루션입니다

<c:when test="${var1.properties['Item Type'] eq 'Animal\'s Part'}"> 

<c:when test='${var1.properties["Item Type"] eq "Animal\'s Part"}'> 
3

당신은이 개 쉬운 선택이 내 용도 :

<%@ 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's Part" /> 
<c:set var="item_treepart" value="Tree's 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> 
관련 문제