0

我有这个带有一些条件的jsp页面:

<%      
        if (filterPresent.equals("true") && !selectedFilterCategory.isEmpty()){
%>
        <c:if test="${entry.category eq param.selectedFilterCategory}">
<%
        }
%>
                RENDER A TABLE WITH ITEMS

<%
        if ( filterPresent.equals("true") && !selectedFilterCategory.isEmpty() ) {
%>
        </c:if>
<%
       }
%>

如果该 filterPresent 值为 true,我只想显示一些项目(与类别匹配的项目)。如果它不存在,我想显示所有项目。

我得到的错误是:

An error occurred at line: 48 in the jsp file: /jsp//ejbChildRule.jsp
Syntax error, insert "while ( Expression ) ;" to complete BlockStatements
45: %>
46:             <c:if test="${entry.category eq param.selectedFilterCategory}">
47: <%
48:             }
49: %>
50:                 <tr class="<%=currentBackground%>">
51:                             <td  class="<%=currentBackground%>" align="left" valign="middle" nowrap>

我能以这种方式实现我想要的吗?

4

2 回答 2

1

这看起来相当难看。用于<c:if>所有子句。使用 scriptlet 会导致这些类型的错误 - 未闭合的括号、忘记的分号等。

于 2011-10-07T11:55:39.827 回答
0

您不应该使用任何 scriptlet,除非在非常紧急的情况下。

而不是<%=currentBackground%>你可以使用:

  • Java bean 中的 request.setAttribute("currentBackground", yourObject)
  • 或使用带有 getter/setter 的Bean

然后正确使用表达式语言和 ${currentBackground} 来获取你的对象。

于 2011-10-07T15:15:41.450 回答