向JSP添加IF语句



我试图添加一个if语句到下面的代码,但它一直抛出错误。我做错了什么?

     <%
      int countOnRows = 0;
        int i;
        countOnRows=  Integer.parseInt(formFields.getValue("broughtBack"));
        if (countOnRows = 0) {
        <h2>No data available - check back later </h2>
        }
        for( i=1; i<=countOnRows; i++ )
        { %>
                <div class="a_report">
                <h2>Dealer Sales Report</h2>
                <h3>Sales Results as of July 2014 - <%=formFields.getValue("dealerName"+i)%>, Dealer <span class="dlr_info"># <%=formFields.getValue("dealerNo"+i)%></span></h3>
                <div class="body_copy"><span class="print">[ <a href="javascript:window.print()">print this report</a> ]</span>
    :
    : table with table data in report here
    :
    <% } %>
            </div>

这不是Java代码:

if (countOnRows = 0) {
    <h2>No data available - check back later </h2>
}

改成:

if (countOnRows == 0) {
    %> <h2>No data available - check back later </h2> <%
}

我也把if (countOnRows = 0)改成了if (countOnRows == 0)

您应该阅读有关使用JSTL和EL的内容,这比在JSP页面中使用Java代码要好。

最新更新