html - JSP,如何根据它是哪个表单来更改HTML表单名称?
问题描述
我基本上是在尝试根据数据库中有多少项目生成一个表单,我如何让每个表单名称唯一,我的想法是称之为“bid1”......“bid2”......通过使用“bid”+ item_id 创建一个字符串。虽然我不确定如何在 html 中使用字符串。
ResultSet rs = st.executeQuery("select * from auctionItem"); //loads database, already connected
while (rs.next() != false){ // while not end of database
String formname = "bid" + rs.getString(7); //create the formname
if (request.getParameter(formname) != null){ //check If I got input from the form
out.println("got input -------------------------------------------------");//just for testing to see if it ran
int currentBid = Integer.parseInt(rs.getString(6));
int newBid = Integer.parseInt(request.getParameter(formname));
if (newBid > currentBid){ //checks if bid is larger then current bid
int i = st.executeUpdate("UPDATE autionItem SET currentBid = " + newBid); //Im trying to use this to change the bid but I dont think that its getting the input
}
}
PRODUCT: <%= rs.getString(1) %> //outputs each item in table
DESCRIPTION: <%= rs.getString(2) %> <br>
SOLD BY: <%= rs.getString(3) %> <br>
Listed: <%= rs.getString(4) %>
Ends: <%= rs.getString(5) %><br>
Current Bid: <%= rs.getString(6) %> //Below is basically if they are logged in show the forms
Place Bid: <%if (session.getAttribute("loggedIn") == "true") { %><form method = "post" action = "mainSite.jsp"><input type="text" name="<%formname%>"><input type = "submit"></form>
<%}
else out.println("Log in or register to bid!");
%>
解决方案
推荐阅读
- java - java 编译器是否理解 if 语句中给出的条件?
- java - BuilderExample 类型的方法 builder() 未定义
- r - 使用复选框以闪亮的方式显示数据子集
- sql - 从表名和值是参数 SQL 的查询中检索信息
- python - 如何设置激活环境的jupyter实验室路径
- javascript - node-red 循环遍历全局变量
- javascript - asp.net mvc 如何将视图模型和输入文本传递给控制器?
- postgresql - 错误:致命:角色“登录”不存在
- sql-server - 通过 Informatica 更新数据库中的特定表在特定时间间隔内需要很长时间
- c++ - 使用函数数据类型键入别名和别名模板