<form id="send" action="doaddnewuser.jsp" method="post">
<div id="controls" style="background-color:#FFFFFF;height:500px;width:750px;float:left;">
<table>
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<%
String buffer = "<tr><td><label for=''" + "productid" + "''>Product ID *</label></td> <td><select name='" + "productid" + "'>";
try {
Class.forName("oracle.jdbc.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/XE", "*****", "*****");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("Select * from product");
while (rs.next()) {
buffer = buffer + "<option value='" + rs.getString(1) + "'>" + rs.getString(1) + "</option>";
}
buffer = buffer + "</select> </td></tr>";
response.getWriter().println(buffer);
} catch (Exception e) {
System.out.println(e);
}
%>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><label for="price">Price *</label></td>
<td><input type="text" name="price" value="" size="60"/></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><label for="debitaccount">Debit Account *</label></td>
<td><input type="text" name="debitaccount" value="" size="25" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><label for="creditaccount">Credit Account *</label>
<td><input type="text" name="creditaccount" value="" size="25" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><label for="quantity">Quantity *</label></td>
<td><input type="text" name="quantity" value="1" size="25" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><label for="transactiondate">Transaction Date *</label></td>
<td><input type="date" name="transactiondate" value="" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><label for="totalprice">Total Price *</label></td>
<td><input type="text" name="totalprice" value="" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><label for="vat" style="text-align:justify" >15% VAT</label></td>
<td><input type="text" name="vat" value="" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td></td>
<td>
<input id ="submit" type="submit" value="Save" name="submit" />
</td>
</tr>
</tbody>
</table>
</div>
</form>
以上是构建销售输入表单的HTML和JSP代码 - 但是当页面运行时,由JSP构造的产品ID字段将转到左上角而不是 与其他控件一起显示
你可以帮我解释它为什么会徘徊。P.S。我们的想法是从数据库中填充product_id字段
答案 0 :(得分:0)
不要在jsp中使用response.getWriter().print(..)
,而是执行下面的代码。
<%
String buffer = "<tr><td><label for=''" + "productid" + "''>Product ID *</label></td> <td><select name='" + "productid" + "'>";
try {
Class.forName("oracle.jdbc.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/XE", "*****", "*****");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("Select * from product");
while (rs.next()) {
buffer = buffer + "<option value='" + rs.getString(1) + "'>" + rs.getString(1) + "</option>";
}
buffer = buffer + "</select> </td></tr>";
} catch (Exception e) {
System.out.println(e);
}
%>
<%=buffer%>
<%=buffer%>
将在页面中打印缓冲区变量的内容。
答案 1 :(得分:0)
然后我建议你这样做:
<form id="send" action="doaddnewuser.jsp" method="post">
<div id="controls" style="background-color:#FFFFFF;height:500px;width:750px;float:left;">
<table>
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>
<label for=''" + "productid" + "''>Product ID *</label></td> <td><select name='" + "productid" + "'>
<%
try {
Class.forName("oracle.jdbc.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/XE", "*****", "*****");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("Select * from product");
while (rs.next()) {
%>
<option value = "<%=rs.getString(1)%>"> <%=rs.getString(1)%> </option>
<%
}
} catch (Exception e) {
System.out.println(e);
}
%>
</select> </td></tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><label for="price">Price *</label></td>
<td><input type="text" name="price" value="" size="60"/></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><label for="debitaccount">Debit Account *</label></td>
<td><input type="text" name="debitaccount" value="" size="25" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><label for="creditaccount">Credit Account *</label>
<td><input type="text" name="creditaccount" value="" size="25" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><label for="quantity">Quantity *</label></td>
<td><input type="text" name="quantity" value="1" size="25" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><label for="transactiondate">Transaction Date *</label></td>
<td><input type="date" name="transactiondate" value="" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><label for="totalprice">Total Price *</label></td>
<td><input type="text" name="totalprice" value="" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><label for="vat" style="text-align:justify" >15% VAT</label></td>
<td><input type="text" name="vat" value="" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td></td>
<td>
<input id ="submit" type="submit" value="Save" name="submit" />
</td>
</tr>
</tbody>
</table>
</div>
</form>