0

我必须从服务器检查一个属性,并且根据值,我必须设置字体的颜色。我用于相同的代码是:我在 jstl 中很新。可以用 javascript 或者 jQuery 处理,但是有一个限制,这里不能用 js。:(

 <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)
4

2 回答 2

2

以下行不正确。你已经写了两次“测试”;-)

<c:when test=test="${error_code eq 'success'}">
于 2013-09-30T08:50:51.860 回答
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>
于 2013-09-30T09:23:21.717 回答