无法在表

时间:2015-07-14 08:40:34

标签: java jsp

我有以下JSP

<table>
        <thead>
            <th>Patient ID</th>
            <th>Name</th>
            <th>Address</th>
            <th>Contact No</th>
            <th>Disease</th>
            <th>Doctor Assigned</th>
            <th>Date</th>
            <th>Room Assigned</th>
        </thead>

        <%
            String Query = "Select ID, Name, address, contactnumber,disease,DOCASSIGN,JOINING, ROOMASSIGN from patient";
            PreparedStatement ps = conn.prepareStatement(Query);
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
        %>
        <tr>
            <td>
                <%
                    out.print(rs.getInt(1));
                %>
            </td>
            <td>Hi</td>
        </tr>
        <%
            }
        %>
    </table>

我正在运行查询并将数据放入表td。查询运行正常问题是,如果我使用<td><%out.print(rs.getInt(1));%></td>,则值会显示在td中,但是当我尝试使用<td><%rs.getInt(1);%></td>获取时,{{1}显示空白。

我想知道如果在jsp中显示值,我们必须确保使用td,或者我可以使用out.print()直接显示值。

1 个答案:

答案 0 :(得分:2)

在JSP中显示值有两种基本方法。首先,如您所述,您可以在<%%>之间执行代码。如果您在那里使用out.printout.println,它将显示在您的页面上:

<% out.print(rs.getInt(1)); %>

或者,您可以在<%=%>之间添加表达式(请注意=!)。此表达式将只打印到页面:

<%= rs.getInt(1) %>
相关问题