Home > Blockchain >  How to submit data via Form in a For-Loop?
How to submit data via Form in a For-Loop?

Time:06-29

I have a method that prints a table with values of 7 columns. I wanted the data of the fifth columns to be a link, that when i click on them i get directed to another page, where I have more details about that specific value.

for (int i = 1; i <= col; i  ) {
            // columnnnames being written
            table  = "<th>"   firstUpper(rsmd.getColumnName(i))   "</th>";
        }
        // close head of table
        table  = "</tr>"   "</thead>";
        // Eigentliche Inhalte werden gefuellt
        do {
            // Start 1.Row
            table  = "<tr>";
            // For Loop through all values
            for (int i = 1; i <= col; i  ) {
                // if column 5, put in a form
                if (i == 5) { 
                    table  = "<td>"   "<form method=\"POST\" action=\"seminarDetailansichtServlet\">" 
                   "<input type=\"text\" name=\"titel\" value=\"rs.getString(i)\" readonly>"   "<input type=\"submit\" value=\"Detailansicht\">"
                  "</form>"   "</td>";
                    System.err.print("der kommt an");
                } else {
                    table  = "<td>"   rs.getString(i)   "</td>";
                
                }
            }
            table  = "</tr>";
        } while (rs.next());

so I can submit the specific value i clicked on to get more details of it in my seminarDetailansicht.jsp. But when I'm running my program, it shows in the input fields "rs.getString(i)" instead of the real value (title). Is there another possibility to submit the value or what am I doing wrong that it doesn't show the actual value?

Thanks

CodePudding user response:

The reason is rs.getString(i) is inside the double quote so it's just part of a string. You want to concat the result of rs.getString(i) to the string.

For example:

"<input type=\"text\" name=\"titel\" value=\"" rs.getString(i) "\" ...

  • Related