开发者

JSP using JSTL and scriptlets

开发者 https://www.devze.com 2023-04-11 22:27 出处:网络
I have this jsp page with some condi开发者_JS百科tions : <% if (filterPresent.equals(\"true\") && !selectedFilterCategory.isEmpty()){

I have this jsp page with some condi开发者_JS百科tions :

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

If that filterPresent value is true I want only some items to be displayed(those that match the category). If it is not present I want to display all the items.

The error I'm getting is :

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>

Can I achieve what I want in this manner ?


That looks rather ugly. Use <c:if> for all the clauses. Using scriptlets leads to these kinds of mistakes - unclosed brackets, forgotten semicolons, etc.


you should NOT use any scriptlets, except under very urgent circumstances.

Instead of <%=currentBackground%> you may use :

  • request.setAttribute("currentBackground", yourObject) inside your Java beans
  • or useBean with getter/setter

then properly use Expression Language with ${currentBackground} to fetch yourObject.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号