这么写正确吗<script> var status <c:if test="${fyTestUser.status ==1}">status='工作中'</c:if> <c:if test="${fyTestUser.status ==2}">status='放假中'</c:if> <c:if test="${fyTestUser.status ==3}">status='已离职'</c:if> </script>
时间: 2023-05-22 19:05:40 浏览: 94
这段代码的语法有误,应该加上等号将变量 status 赋值。正确的代码应该是:
<script>
var status = '';
<c:if test="${fyTestUser.status ==1}">status='工作中';</c:if>
<c:if test="${fyTestUser.status ==2}">status='放假中';</c:if>
<c:if test="${fyTestUser.status ==3}">status='已离职';</c:if>
</script>
相关问题
<tr> <td> 附件: <c:forEach var="fileName" items="${fileName}" varStatus="status"> <c:out value="${fileName}" /> <c:if test="${!status.last}">、</c:if> </c:forEach> </td> </tr>如果值为空就把这个tr标签隐藏
你的问题是如何判断值为空并隐藏这个tr标签。可以通过以下代码实现:
```
<c:if test="${empty fileName}">
<tr style="display:none;">
<td>附件:</td>
</tr>
</c:if>
<c:if test="${not empty fileName}">
<tr>
<td>附件:
<c:forEach var="fileName" items="${fileName}" varStatus="status">
<c:out value="${fileName}" />
<c:if test="${not status.last}">、</c:if>
</c:forEach>
</td>
</tr>
</c:if>
```
这样,如果值为空,就会隐藏这个tr标签。
在struts2 2.3.15.1版本中将jsp页面中的<c:if test="${empty pageFinder.data }"> <tr><td colspan=13 align="center” height="25"xfont color="red"没有查询到相关记录</f</c:if> <s:iterator value="%{pageFinder.data}" var="rehs” status="status"><s:set var="index”value="#status getIndex()"/> 这段代码中的<s:iterator value="%{pageFinder.data}"改为<s:iterator value="${pageFinder.data}"系统会报does not accept any expressions这个错误,是什么原因?
在Struts2中,当使用`${}`表达式时,它会被解析为OGNL表达式,而非JSP表达式。而在JSP页面中使用的`<c:if>`标签和`<s:iterator>`标签是JSTL标签和Struts2标签,它们并不支持OGNL表达式。因此,将`<s:iterator>`标签中的`%{}`改为`${}`会导致系统报错。正确的做法是保留`%{}`。