在jsp中显示条件的html代码

时间:2015-01-09 07:53:12

标签: jsp

当DB结果为null时,我想将html标签附加到jsp页面。我使用out.write()out.print(),但这些函数有任何结果。

这是我的jsp代码:

<div id="result">
            <label>Trend:</label> <select class="form-control"
                disabled="disabled" style="width: 200px;"><option><%=session.getAttribute("building").toString()%></option></select>
            <label>Year: </label>
            <%
                String tab = null, courseid = null;
               int cnt=0;
                String building = session.getAttribute("building").toString();
                //System.out.println("\n" + building);
                {
                    ResultSet rs = new report2().year_in_dept(building);
                    while (rs.next()) {
                        cnt++;
                    }

                }
                ResultSet rs = new report2().year_in_dept(building);
            %>
            <br />

            <div style="width: 200px;">
                <select id="yearlist" class="form-control">
                    <%
                        String id = null;
                        if (cnt>0) {
                            while (rs.next()) {
                    %>
                    <option style="color: red;" value="<%=rs.getString("year")%>">
                        <%
                            System.out.println(rs.getString("year"));
                                    out.println(rs.getString("year"));
                        %>
                    </option>

                    <%
                        }
                        }
                        else{
                            out.print("<div class=\"col-md-7 col-md-offset-3\" id=\"error\" style=\"margin-top:-600px;\">"
                                    + "<div id=\"alertbar\" class=\"alert alert-danger alert-dismissible\" role=\"alert\">"
                                    + "<button type=\"button\" class=\"close\" data-dismiss=\"alert\">"
                                    + "<span aria-hidden=\"true\">&times;</span><span class=\"sr-only\">Close</span>"
                                    + "</button>"
                                    + "<strong>Warning!</strong> In your selected semester and year not exist."
                                    + "</div>"
                                    + "</div>");
                            System.out.print("kkk");
                        }
                    %>
                </select> <label>Semester:</label> <select class="form-control"
                    style="width: 200px;" id="semester">
                    <option style="color: red;" value="Fall">Fall</option>
                    <option style="color: red;" value="Spring">Spring</option>
                </select>
            </div>
            <br> <input type="submit" class="btn btn-default"
                id="showresult" value="Show Result">
            <div id="container"
                style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"
                data-highcharts-chart="0"></div>
        </div>

我希望这个结果打印在我确定的位置,现在我不知道该怎么做。

0 个答案:

没有答案