Java 当/否则语句出现多个条件时出现JSTL错误
在我的jsp页面上遇到此错误Java 当/否则语句出现多个条件时出现JSTL错误,java,jsp,jstl,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
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'}">
发生未知错误。
weblogic.servlet.jsp.CompilationException:未能编译jsp/deployed/Student/resources/StudentUpdate.jsp
StudentUpdate.jsp:1163:3:该页面未能通过验证程序验证:“tag='out'/attribute='value”:解析值为“${other_-place_-birth==null?”的自定义操作属性“value”时出错。“:other_-place_-birth}”:遇到“?”,应为[“}”,“,”>,“gt”中的一个
错误指向第一个when条件,我不确定when语句中是否允许多个条件。感谢您的帮助否。
没有问题
<input type="text" size=41 maxlength=66 name="birthPlaceT" value="<c:out value="${other_place_birth==null?'':other_place_birth}"/>">
↑
或者您可以使用empty
运算符
<input type="text" value="${empty other_place_birth ? '' : other_place_birth}">
出生地
如有其他,请注明备注
问题在于你的c:out,而不是c:when
c:out中不能有三元(或任何其他)条件。它仅用于显示值。'=='更改为eq
'==' 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>
Hi Anil,谢谢这一个对我有用…不过还有一些问题,但应该是次要的。很乐意帮助:)Hi Aniket,我喜欢这个解决方案,但是我需要使用c:out。谢谢anyway@dimas:不客气:)请不要在JSP中使用scriptlets
。我在您的问题中看到了一个。
<input type="text" value="${empty other_place_birth ? '' : other_place_birth}">
<tr>
<td width="17%" class=label > <b>Place of Birth</b> </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>
'==' 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>