簡體   English   中英

如何將JSP頁面中的此表單提交給servlet?

[英]How can I submit this form that is inside a JSP page to a servlet?

我在JSP頁面開發中還很陌生,對於如何解決此任務,我有以下疑問。

我有一個JSP頁面 ,其中包含一個JQuery手風琴菜單 ,類似這樣:

在此處輸入圖片說明

這是呈現此手風琴菜單的代碼:

    <div id="accordion">

        <%
            for (SalDettaglio salDettaglio : (SalDettaglio[]) request.getSession(false).getAttribute("salDettaglio")) {
        %>
                <h2>
                    <!-- <span>SALDETTAGLIO: </span> -->  <%-- out.println(salDettaglio.getCodice()); --%>
                    <!--
                    <table class="salDettaglio" border="1" width="100%">

                        <tr class="salDettaglioRow">
                            <td width = "8.3%"><%=salDettaglio.getCodice()%></td>
                            <td width = "8.3%"><%=salDettaglio.getStato()%></td>
                            <td width = "8.3%"><%=salDettaglio.getDataCreazione()%></td>
                            <td width = "8.3%"><%=salDettaglio.getDataRegistrazione()%></td>
                            <td width = "8.3%"><%=salDettaglio.getAutoreCreazione()%></td>
                            <td width = "8.3%"><%=salDettaglio.getAutoreConvalida()%></td>
                            <td width = "8.3%"><%=salDettaglio.getAutoreAcquisizione()%></td>
                            <td width = "8.3%"><%=salDettaglio.getTotImponibile().toString()%></td>
                            <td width = "8.3%"><%=salDettaglio.getFornitore()%></td>
                            <td width = "8.3%"><%=salDettaglio.getRmConRiserva()%></td>
                            <td width = "8.3%"><%=salDettaglio.getErrore()%></td>
                            <td width = "8.3%">
                                <button class="acceptButton">ACCEPT ICON BUTTON</button>
                                <button class="cancelButton">CANCEL ICON BUTTON</button>
                                <button class="sapButton">SAP ICON BUTTON</button>
                            </td>
                        </tr>
                    </table>
                    -->
                    <table class="standard-table-cls" border="1" width="100%">
                        <thead>
                            <tr class="salDettaglioRow">
                                <th width = "8.33%"><%=salDettaglio.getCodice()%></th>
                                <th width = "8.33%"><%=salDettaglio.getStato()%></th>
                                <th width = "8.33%"><%=salDettaglio.getDataCreazione()%></th>
                                <th width = "8.33%"><%=salDettaglio.getDataRegistrazione()%></th>
                                <th width = "8.33%"><%=salDettaglio.getAutoreCreazione()%></th>
                                <th width = "8.33%"><%=salDettaglio.getAutoreConvalida()%></th>
                                <th width = "8.33%"><%=salDettaglio.getAutoreAcquisizione()%></th>
                                <th width = "8.33%"><%=salDettaglio.getTotImponibile().toString()%></th>
                                <th width = "8.33%"><%=salDettaglio.getFornitore()%></th>
                                <th width = "8.33%"><%=salDettaglio.getRmConRiserva()%></th>
                                <th width = "8.33%"><%=salDettaglio.getErrore()%></th>
                                <th width = "8.33%">
                                    <button class="acceptButton">ACCEPT ICON BUTTON</button>
                                    <button class="cancelButton">CANCEL ICON BUTTON</button>
                                    <button class="sapButton">SAP ICON BUTTON</button>
                                </th>
                            </tr>
                        </thead>
                    </table>
                </h2>

                <div>
                    <table border="1" align="right" class="standard-table-cls">
                        <caption><div align="center"><b>RM</b></div></caption>

                        <thead>
                            <tr>
                                <th width="14.2%">Codice RM</th>
                                <th width="14.2%">Autore Firma</th>
                                <th width="14.2%">Data Firma</th>
                                <th width="14.2%">Acq Riserva</th>
                                <th width="14.2%">Consegna Finale</th>
                                <th width="14.2%">Descrizione RM</th>
                                <th width="14.2%">Imponibile</th>
                            </tr>
                        </thead>

                        <%
                        for (RM currentRM : salDettaglio.getRM()) {
                            String test = currentRM.getAcqRiserva();
                        %>

                                <tr id="rmRow">
                                    <td><%=currentRM.getCodiceRm()%></td>
                                    <td><%=currentRM.getAutoreFirma()%></td>
                                    <td><%=currentRM.getDataFirma()%></td>
                                    <td><%=currentRM.getAcqRiserva()%></td>
                                    <td><%=currentRM.getConsegnaFinale()%></td>
                                    <td><%=currentRM.getDescrizioneRM()%></td>
                                    <td><%=currentRM.getImponibile().toString()%></td>
                                </tr>

                    <%}%>
                    </table>
                </div>
        <%
            }
        %>

   </div>

正如您在放在手風琴標題內的表的最后一列中的前一個圖像中看到的那樣,使用JQuery按鈕實現了3個圖標 ,這些圖標是:

<th width = "8.33%">
    <button class="acceptButton">ACCEPT ICON BUTTON</button>
    <button class="cancelButton">CANCEL ICON BUTTON</button>
    <button class="sapButton">SAP ICON BUTTON</button>
</th>

現在,我要做的就是向一個處理此視圖的servlet提交一個值(此時,對於esample,甚至是一個固定值:第一個按鈕1個,第二個按鈕2個,第三個按鈕3個)被點擊。

我認為我必須使用在郵寄后提交的表格。 但是我到底該怎么辦? 在線搜索我創建了這篇文章: http : //www.tutorialspoint.com/jsp/jsp_form_processing.htm

但是在上一教程中,展示了如何將HTML頁面中的表單提交到JSP,但這不是我想要的。

如何將表單提交到JSP中到servlet?

TNX

您可以使用Jquery $.post ajax請求來實現此目的:

<table>
   <td><input type="text" value="test" id="name" />
   <td><button onclick="post(<%=entity.id%>)">submit</button><td>
</table>

<script>
  function post(id){
     var name=$("#name").val();

     $.post(
        "/myservlet", { customerid: id, customername: name }
     ).done(function(data){
        alert(data);
       //This will send get request to your servlet. can use this if your previous
       //post request done any update in DB
       window.location.href='/myservlet?customerid='+id;
     });
  }
</script>

暫無
暫無

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

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