何时/否则声明多个条件时出现JSTL错误

时间:2014-01-14 05:53:37

标签: java jsp jstl

在我的jsp页面上遇到此错误

An unknown error has occured. 
weblogic.servlet.jsp.CompilationException: Failed to compile JSP /deployed/Student/resources/StudentUpdate.jsp
StudentUpdate.jsp:1163:3: The page failed validation from validator: "tag = 'out' / attribute = 'value': An error occurred while parsing custom action attribute "value" with value "${other_place_birth==null?'':other_place_birth}": Encountered "?", expected one of ["}", ".", ">", "gt", "<", "lt", "==", "eq", "<=", "le", ">=", "ge", "!=", "ne", "[", "+", "-", "*", "/", "div", "%", "mod", "and", "&&", "or", "||"]".
<c:when test="${birth_place_code != null && birth_place_code == '99'}">

这是我的代码

 <tr> 
    <td width="17%" class=label > <b>Place of Birth</b>&nbsp; </td>
    <td colspan="3" class=value> <div align="left"> <%=HtmlUtil.setListOptions("birthPlace","onchange ='javascript:SetEnabled()'",birth_place_option,birth_place_code,true,"")%> 
        if others, please specify remarks
    <c:choose>
        **<c:when test="${birth_place_code != null && birth_place_code == '99'}">**
            <input type="text" size=41 maxlength=66 name="birthPlaceT" value="<c:out value="${other_place_birth==null?'':other_place_birth}"/>">
        </c:when>
        <c:otherwise>
        <input type="text" size=41 maxlength=66 name="birthPlaceT" value=" " disabled>
        </c:otherwise>
    </c:choose>
      </div></td>
  </tr>

错误指向第一个条件时,我不确定when语句中是否允许多个条件。谢谢你的帮助

3 个答案:

答案 0 :(得分:1)

没有。 <c:when>代替

没有问题
<input type="text" size=41 maxlength=66 name="birthPlaceT" value="<c:out value="${other_place_birth==null?'':other_place_birth}"/>">
                                                                               ↑  

value <c:out>属性中的第一个双引号(“)打破了value的{​​{1}}属性。

只需更改为

input

或者您可以使用<input type="text" value="${other_place_birth == null ? '' : other_place_birth}"> 运算符

empty

答案 1 :(得分:1)

    <tr> 
<td width="17%" class=label > <b>Place of Birth</b>&nbsp; </td>
<td colspan="3" class=value> <div align="left"> <%=HtmlUtil.setListOptions("birthPlace","onchange ='javascript:SetEnabled()'",birth_place_option,birth_place_code,true,"")%> 
    if others, please specify remarks
<c:choose>
    <c:when test="${birth_place_code != null && birth_place_code == '99'}">
        <c:when test="${other_place_birth!=null}">
            <input type="text" size=41 maxlength=66 name="birthPlaceT" value="<c:out value="${other_place_birth}"/>">        
        </c:when>
        <c:otherwise>
            <input type="text" size=41 maxlength=66 name="birthPlaceT" value="">           
        </c:otherwise>
    </c:when>
    <c:otherwise>
    <input type="text" size=41 maxlength=66 name="birthPlaceT" value=" " disabled>
    </c:otherwise>
</c:choose>
  </div></td>

问题出在你的c:out。不在c:什么时候 你不能在c:out中有三元(或任何其他)条件。它仅用于显示值。

答案 2 :(得分:0)

'==' change to eq
<c:choose>
    <c:when test="${birth_place_code != null && birth_place_code eq '99'}"> 
        <c:out/>
    </c:when>
    <c:otherwise>
    <input type="text" size=41 value=" " disabled>
    </c:otherwise>
</c:choose>