使用 Java servlet 在每个单元格中使用按钮时如何转到另一个页面
我有一个包含所有数据的表格,我希望它的每个数据单元格都有一个按钮,以便它可以查看更多详细信息。
下面是我目前拥有的表格。
所以我希望它转到另一个页面,网址为 http://localhost:9999/animeShop/query?fname=1
fname 基于手机号码。
//to get sql data
List<Object> dataItems = new ArrayList<Object>();
while (rset.next()) {
SQLData item = new SQLData(rset.getString("name"), rset.getString("prod_desc"),
rset.getDouble("price"));
dataItems.add(item);
}
//for table
out.println("<form method='get' action='http://localhost:9999/animeShop/query'>");
out.println("<table class='table table-bordered'>");
out.println("<tr>");
for (int i = 0; i < dataItems.size(); i++) {
if (i >= 5 && i % 5 == 0) {
out.println("</tr><tr>");
}
int idNum = i + 1;
out.println("<td> <input type='hidden' name='fname' value='" + idNum + "'>"
+ dataItems.get(i) + "<input type='submit' value='Search' /> </td>");
}
out.println("</tr>");
out.println("</table>");
out.println("<form />");
当我单击按钮时,网址如下
http://localhost:9999/animeShop/query?fname=1&fname=2&fname=3&fname=4&fname=5&fname=6
我明白重复 5 次,因为它在循环中,但我想不出将它放在哪里的任何想法。
有人可以帮忙吗?
I have a table with all the data and I want it to have a button for each data cell so that it can view more in detail.
Below is the table i have currently.
So i want it to go to another page with url http://localhost:9999/animeShop/query?fname=1
The fname is based on the cell number.
//to get sql data
List<Object> dataItems = new ArrayList<Object>();
while (rset.next()) {
SQLData item = new SQLData(rset.getString("name"), rset.getString("prod_desc"),
rset.getDouble("price"));
dataItems.add(item);
}
//for table
out.println("<form method='get' action='http://localhost:9999/animeShop/query'>");
out.println("<table class='table table-bordered'>");
out.println("<tr>");
for (int i = 0; i < dataItems.size(); i++) {
if (i >= 5 && i % 5 == 0) {
out.println("</tr><tr>");
}
int idNum = i + 1;
out.println("<td> <input type='hidden' name='fname' value='" + idNum + "'>"
+ dataItems.get(i) + "<input type='submit' value='Search' /> </td>");
}
out.println("</tr>");
out.println("</table>");
out.println("<form />");
When i click on the button, the url is like this
http://localhost:9999/animeShop/query?fname=1&fname=2&fname=3&fname=4&fname=5&fname=6
I understand it is repeated 5 times because it is in the loop but I cannot think of any idea on where to put it.
Anyone can help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您有一张表单,其中有一个目标 URL,但有五个提交按钮。每个按钮都会将所有输入字段的内容作为参数发送回服务器。
吗
你真的有五次 ?您期望它在运行时表现如何?
我建议您选择
As it seems you have one form with one destination URL but five submit buttons. Each of the buttons will send all the input field's content as parameters back to the server.
Is it real that you have
five times? How would you expect this to behave at runtime?
I suggest you go for