2013-09-30 40 views
0

我必須從服務器檢查一個屬性,根據值,我必須設置字體的顏色。我使用的代碼是:我在jstl中很新。可以用javascript或jQuery來處理,但有一個約束,不要在這裏使用js。 :(在jstl錯誤中檢查字符串

<c:if test="${error != null}"> 
     <c:choose> 
      <c:when test="${error_code eq 'failed'}"> 
        <p align="left"><font size="3" color="red">${error}</font></p> 
       </c:when> 

       <c:when test=test="${error_code eq 'success'}"> 
        <p align="left"><font size="3" color="green">${error}</font></p> 
       </c:when> 
     </c:choose> 
    </c:if> 

而服務器端代碼:

if (result) { 
    request.setAttribute("error_code","success"); 
    request.setAttribute("error","Object successfully created."); 
} else { 
    request.setAttribute("error_code","failed"); 
    request.setAttribute("error","Object creation failed."); 
} 

我在做什麼錯在這裏:

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    at java.lang.Thread.run(Unknown Source) 
    org.apache.jasper.JasperException: /tool/Content/content.jsp (li 
    ne: 68, column: 18) **quote symbol expected** 
    at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorH 
    andler.java:42) 
    at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.j 
    ava:443) 
    at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.j 
    ava:89) 

回答

2

以下行不正確你必須寫 「測試」 兩次;-)

<c:when test=test="${error_code eq 'success'}"> 
0

現在它的工作,我將代碼更改爲:

<c:if test="${error != null}"> 
      <c:choose> 
       <c:when test="${fn:containsIgnoreCase(error_code, 'failed')}"> 
        <p align="left"><font size="3" color="red">${error}</font></p> 
       </c:when> 
       <c:when test="${fn:containsIgnoreCase(error_code, 'success')}"> 
        <p align="left"><font size="3" color="green">${error}</font></p> 
       </c:when> 
      </c:choose> 
     </c:if>