Html 表单、单选按钮和 Servlet
我编写了一个 servlet,它构建了一个显示数据库内容的 html 页面。 代码是:
Statement st = (Statement) conexion.createStatement();
ResultSet rs = st.executeQuery("select * from audiolist" );
while (rs.next())
{
contador++;
out.println("<tr>");
String k = rs.getString("Tittle");
String l = rs.getString("Autor");
String m = rs.getString("Album");
out.println("<td>"+"<input type=\"radio\" name=\"titulo<%="+contador+"%>\"value=\""+k+"\">");
out.println("<td>" + k + "</td>");
out.println("<td>" + l + "</td>");
out.println("<td>" + m + "</td>");
out.println("</tr>");
}
out.println("</table></center>");
out.println("<tr><td colspan=2><input type=submit></td></tr>");
out.println("</form>");
我在每一行添加了一个单选按钮。 使用此代码,我可以在浏览器中显示包含数据库内容的表格。 当我单击提交时,我想将所选行的值“k”发送到另一个 servlet。 我很难受这个问题。 我认为我发送的值不正确。 在第二个 servlet 中,使用 getParameter() 来获取信息是否足够?
谢谢!
I've writen a servlet that builds an html page showing the content of a database. The code is:
Statement st = (Statement) conexion.createStatement();
ResultSet rs = st.executeQuery("select * from audiolist" );
while (rs.next())
{
contador++;
out.println("<tr>");
String k = rs.getString("Tittle");
String l = rs.getString("Autor");
String m = rs.getString("Album");
out.println("<td>"+"<input type=\"radio\" name=\"titulo<%="+contador+"%>\"value=\""+k+"\">");
out.println("<td>" + k + "</td>");
out.println("<td>" + l + "</td>");
out.println("<td>" + m + "</td>");
out.println("</tr>");
}
out.println("</table></center>");
out.println("<tr><td colspan=2><input type=submit></td></tr>");
out.println("</form>");
I've added a radio button to each row. With this code I get to show in the browser a table with the content of the database. When I click on submit I want send to another servlet the vale 'k' for the row selected. I'm having a hard time with this. I think I'm sending the value incorrectly. In the second servlet, is it enough to use getParameter() in order to get the info?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在第二个 servlet 中,您可以使用:
来读取值。 您需要知道要执行的操作的参数名称。 如果未知,您可以尝试枚举参数:
这只适用于具有单个值的参数。
In the second servlet you can use:
to read the value. You need to know the name of the parameter to do. If this is not known, you can try to enumerate the parameters:
This only works for parameters with a single value.
这条线正确吗?
Is this line correct?