Jsp JSTL<;c:何时>;及<;选择>;标签
我第一次做JSTL编码,在使用if-else条件(c:when和c:choose)时遇到了一些问题 我需要的if-else嵌套的psuedo代码是Jsp JSTL<;c:何时>;及<;选择>;标签,jsp,jstl,jsp-tags,Jsp,Jstl,Jsp Tags,我第一次做JSTL编码,在使用if-else条件(c:when和c:choose)时遇到了一些问题 我需要的if-else嵌套的psuedo代码是 if(${not empty properties['userrgba']}){ <div style = "background-color: ${properties['userrgba']};"> } else if({not empty properties['userColor']}) {
if(${not empty properties['userrgba']}){
<div style = "background-color: ${properties['userrgba']};">
}
else if({not empty properties['userColor']})
{
if({not empty properties['userColorGradient']}){
<div style = "background-color: ${properties['userColor']};
background: -webkit-gradient(linear, left top, left bottom, color-stop(50%, ${properties['userColorGradient']}));" >
}
else{
<div style = "background-color: ${properties['userColor']};">
}
} //END ELSE IF
else{
<div class = ${properties['color']}>
} //END ELSE
第43行是我最后一次做的地方。我考虑了很多,做了很多修改,但每次出现类似的错误都是某一行或另一行(与关闭choose标记或when标记有关)
有什么办法可以修吗
谢谢 更好地缩进您的代码,这样就可以清楚地知道这些事情的开始和结束。没有适当的缩进就不可能找到问题 下面是您的原始代码
<c:choose>
<c:when test="${not empty properties['userrgba']}">
<div style = "background-color: ${properties['userrgba']};">
</c:when>
<c:otherwise>
<c:choose>
<c:when test="${not empty properties['userColor']}">
<c:choose>
<c:when test="${not empty properties['userColorGradient']}">
<div style = "background-color: ${properties['userColor']};
background: -webkit-gradient(linear, left top, left bottom, color-stop(50%, ${properties['userColorGradient']}));">
</c:when>
<c:otherwise>
<div style = "background-color: ${properties['userColor']};">
</c:otherwise>
</c:choose>
</c:when>
</c:choose>
<c:otherwise> //<-- this should be </c:otherwise>
<c:otherwise>
<div class = ${properties['color']}>
</c:otherwise>
</c:choose>
// 更好地缩进您的代码,以便清楚这些事情的开始和结束。没有适当的缩进就不可能找到问题
下面是您的原始代码
<c:choose>
<c:when test="${not empty properties['userrgba']}">
<div style = "background-color: ${properties['userrgba']};">
</c:when>
<c:otherwise>
<c:choose>
<c:when test="${not empty properties['userColor']}">
<c:choose>
<c:when test="${not empty properties['userColorGradient']}">
<div style = "background-color: ${properties['userColor']};
background: -webkit-gradient(linear, left top, left bottom, color-stop(50%, ${properties['userColorGradient']}));">
</c:when>
<c:otherwise>
<div style = "background-color: ${properties['userColor']};">
</c:otherwise>
</c:choose>
</c:when>
</c:choose>
<c:otherwise> //<-- this should be </c:otherwise>
<c:otherwise>
<div class = ${properties['color']}>
</c:otherwise>
</c:choose>
//谢谢你建议缩进编辑,我更新了我原来的帖子。我不确定我错在哪里。这是我第一次做jstl。“//@user3861559,c:choose
是一个类似的案例
(即开关案例)在C/C++/Java中,和C:others
类似于default
:每个开关盒只能有一个default
。@user3861559,问题是您的伪代码甚至是错误的。一个if statmenet不能有两个else
块。而不是else
本身(与else if
相反)。你上一次的else
是错误的:删除它。嗨!我的错。我本来想在那里有一个if-else标记。我成功了。谢谢你的帮助。谢谢你建议缩进编辑,我更新了我的原始帖子。我不确定我哪里出错了。这是我第一次使用jstl。“/@user3861559,c:choose
在c/c++/Java中类似于case
(即开关case),而c:other
类似于default
:每个开关case只能有一个default
。@user3861559,问题是您的伪代码甚至是错误的。一个if statmenet不能有两个else
块。本身不else
(与else相反,如果)。您最后的else
错误:删除它。嗨!我的错。我本来想在那里贴个if-else标签的。我让它工作了。谢谢你的帮助。
<c:choose>
<c:when test="${not empty properties['userrgba']}">
<div style = "background-color: ${properties['userrgba']};">
</c:when>
<c:otherwise>
<c:choose>
<c:when test="${not empty properties['userColor']}">
<c:choose>
<c:when test="${not empty properties['userColorGradient']}">
<div style = "background-color: ${properties['userColor']};
background: -webkit-gradient(linear, left top, left bottom, color-stop(50%, ${properties['userColorGradient']}));">
</c:when>
<c:otherwise>
<div style = "background-color: ${properties['userColor']};">
</c:otherwise>
</c:choose>
</c:when>
</c:choose>
<c:otherwise> //<-- this should be </c:otherwise>
<c:otherwise>
<div class = ${properties['color']}>
</c:otherwise>
</c:choose>