2016년 4월 19일 화요일

[JSP EL] JSP 문자 비교시 예외 발생 / jsp test char exception

- jsp test char exception
- javax.servlet.jsp.el.ELException: An exception occurred trying to convert String "x" to type "java.lang.Long"




<c:when test="${value eq 'x'}">

JSP에서 위와 같은 단순한 비교문을 사용했는데, 아래와 같은 예외가 발생헀다


javax.servlet.jsp.el.ELException: An exception occurred trying to convert String "x" to type "java.lang.Long"


찾아보니 Expression Language Specification 2.2에 char를 Long으로 비교한다고 명시 되어있다.
(1.8.1 단락 / 13 페이지)

=================================================
1.8.1 A {<,>,<=,>=,lt,gt,le,ge} B
■ If A==B, if operator is <=, le, >=, or ge return true.
■ If A is null or B is null, return false
■ If A or B is BigDecimal, coerce both A and B to BigDecimal and use the return
value of A.compareTo(B).
■ If A or B is Float or Double coerce both A and B to Double apply operator
■ If A or B is BigInteger, coerce both A and B to BigInteger and use the return
value of A.compareTo(B).
Chapter 1 Language Syntax and Semantics 13
■ If A or B is Byte, Short, Character, Integer, or Long coerce both A and B to
Long and apply operator
■ If A or B is String coerce both A and B to String, compare lexically
■ If A is Comparable, then:
■ If A.compareTo(B) throws exception, error.
■ Otherwise use result of A.compareTo(B)
■ If B is Comparable, then:
■ If B.compareTo(A) throws exception, error.
■ Otherwise use result of B.compareTo(A)
■ Otherwise, error
=================================================




해결 방법은 아래와 같이 .charAt(0) 부분을 추가해주면 된다

<c:when test="${value eq 'x'.charAt(0)}">






참고 :
http://download.oracle.com/otn-pub/jcp/expression_language-2.2-mrel-eval-oth-JSpec/expression_language-2_2-mrel-spec.pdf
http://www.coderanch.com/t/569524/JSP/java/Issues-Character-comparison-JSTL

댓글 없음:

댓글 쓰기