简体   繁体   中英

JSTL error on when / otherwise statement multiple condition

Encountered this error on my jsp page

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'}">

Here is my Code

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

The error points to the first when condition, am not sure if multiple conditions are allowed in when statements. Thanks for the help

No. There is no problem with <c:when> instead

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

First double quote (") inside the value attribute of <c:out> breaking the value attribute of input .

Just change to

<input type="text" value="${other_place_birth == null ? '' : other_place_birth}">

or you can use empty operator

<input type="text" value="${empty other_place_birth ? '' : other_place_birth}">
    <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>

Problem is in your c:out. Not in c:when You cant have ternary (or any other) conditions in c:out . It is used only to display values.

'==' 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM