Spring (STS4) <c:choose>태그 안쪽 주석 오류

Back-End/Problems 2019. 6. 17. 14:53
728x90
반응형

HTTP Status 500 – Internal Server Error


Type Exception Report

Message <h3>Validation error messages from TagLibraryValidator for [c] in [/WEB-INF/views/home.jsp]</h3><p>56: Illegal text inside "c:choose" tag: "<!-- 초이...".</p>

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception




  log 내용


  ervlet.service() for servlet [appServlet] in context with path [/spring02] threw exception [<h3>Validation error messages from   TagLibraryValidator for [c] in [/WEB-INF/views/home.jsp]</h3><p>56: Illegal text inside "c:choose" tag: "<!-- ch...".</p>] with root    

 cause

  org.apache.jasper.JasperException: <h3>Validation error messages from TagLibraryValidator for [c] in [/WEB-INF/views/home.jsp]      

  </h3>  

  <p>56: Illegal text inside "c:choose" tag: "<!-- ch...".</p>

at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:55)





  오류 발생 이유


  <!-- -->주석은 html에서 주석을 처리하는 방식이기 때문에 jsp 코드에서는 이것을 주석으로 인식하지 않고 있는 

  그대로 코드를 읽기 때문에 <c:choose>태그 안에 있는 <!-- -->주석 방식 때문에 오류가 발생했음.

  따라서 <!-- --> 로 처리하는 방법을 <%-- -->로 처리하는 식으로 바꾸면 오류가 발생하지 않는다.


  (jsp에서는 주석처리를 <!-- -->로 해도 주석처리를 한 것과 똑같은 색깔이 되지만 실제로는 주석처리가 되지 않기 때문에 

  <%-- -->주석 방식을 사용해야 한다.


  => 하지만 <c:when>태그 안에도 <!-- -->가 있는데 오류가 발생하지 않음... 블로그에서는 안된다고 나와있지만 실행했을때 문제는 없었음





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<c:choose>
    <!-- 초이스태그는 조건에 따른 여러곳으로 분기가 가능하다. -->
<%-- 초이스태그는 조건에 따른 여러곳으로 분기가 가능하다.-->
    <c:when test="${sessionScope.userid == null }">
    
    <!-- when은 test안의 값이 참일때 실행 -->
    <!-- userid 가 null일때 실행한다. 즉 아무것도 안들어있을때 -->
        <a href="${path}/member/login.do">로그인</a> | 
        <a href="${path}/admin/login.do">관리자 로그인</a>
    </c:when>
    
    <c:otherwise>
    <!-- otherwise는 초이스태그 안에 들어가면 default문 같은 역할을 하게 된다. -->
    <!-- 그러니까 위의 초이스태그 안에 구문이 실행이되면 기본으로 나오게 되는 코드가 아래에 있다고 생각하면 된다. -->
    <!-- 로그인 중입니다. 표시와 로그아웃표시는 로그인 중에만 출력이 되야하기 때문에 oterwiser구문을 사용한다. -->
        ${sessionScope.name}님이 로그인중입니다.
        <a href="${path}/member/logout.do">로그아웃</a>
    </c:otherwise>
    
    
</c:choose>
cs


728x90
반응형
: