簡體   English   中英

使用jsp將數據從動態表獲取到另一頁

[英]To get data to another page from a dynamic table by use of jsp

下表是使用jsp動態創建的,我已共享下面的代碼。 我希望在按下按鈕時在另一頁上獲得我選擇的所需值。

code:

<form action="quotation.jsp" method="post">
    <table class="highlight centered responsive-table">
        <thead>
            <tr>
        <%  
            int i=0;
            int j=0;
            while(rs1.next())
            {
                i++;
                out.print("<th>"+rs1.getString(1)+"</th>");
            }
            j=i;
        %>
            <th> Quotation </th>
            </tr>
        </thead>
        <tbody>
        <% 
            while(rs2.next())
            {
                out.println("<tr>");
                for(int q=1;q<=j;q++)
                {   
                    out.print("<td>"+rs2.getString(q)+"</td>");
                }
                %>
                    <td> <button class="btn waves-effect waves-light" type="submit" name="submit">Quotation</button> </td>          
                <%  
                out.println("</tr>");
            }                   
          %>
          </tbody>
      </table>  
</form>      
</div>    

在按下按鈕時,我要獲取下一頁中特定行的選定列的數據。

為了使用jsp將數據從一頁移動到另一頁,可以使用會話管理或HttpServletRequest對象請求。

使用HttpServletRequest:

您可以使用javascript,以下javascript函數將提醒html表行索引。

function saveRowID(row){

     alert(row.parentNode.parentNode.rowIndex);
     return false ;
}

您的HTML按鈕代碼將為:

<button class="btn waves-effect waves-light" type="submit" name="submit" onclick="saveRowID(this)"></button>

在javascript函數中,row參數包含表行中所有td或th元素的集合。 您可以遍歷它們,並將值保存在html表單隱藏字段中,然后提交此表單。 在jsp標記的其他頁面上,使用HttpServletRequest請求對象獲取表單字段值,如下所示:

 request.getParameter("formFieldId")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM