在下面的代码中,我希望用户选择至少 1 个复选框,然后将该输入与输入的 product_id 一起输入,并将它们插入两个不同的表中。所以我遇到的问题是从视图/jsp页面和servlet中的查询语句传递多个component_id
<%
List<Component> components = new ArrayList<Component>();
components = ComponentDb.selectComponents();
for (Component component : components) {
%>
<tr>
<td></td>
<td><input type="checkbox" name="component_id" value="
<%=component.getId()%>" required="required"><%=component.getName()%></td>
//here i have the end of form and stuff i doubt its necessary
我的servlet是(就这一点而言)
String query = "insert into Product
(product_id,product_name,product_description,product_price) VALUES
('"+product_id+"','"+product_name+"','"+product_description+"','"+product_price+"');"+
"insert into PC(product_id,component_id) VALUES
("+product_id+","+component_id+")";
//kinda puzzled here on how to pass the values seperately
try {
ps = connection.prepareStatement(query);
int a = ps.executeUpdate(query);
谢谢