将IF语句添加到JSP

时间:2014-07-02 17:18:39

标签: html jsp if-statement

我正在尝试向以下代码添加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>

1 个答案:

答案 0 :(得分:0)

这不是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)

您应该阅读有关使用JSTLEL的内容,它比在JSP页面中使用Java代码更好。