首页 > 解决方案 > 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!");
                    %>

标签: htmlsqlformsjsp

解决方案


推荐阅读