[英]How can I submit this form that is inside a JSP page to a servlet?
I am pretty new in JSP page development and I have the following doubt about how to solve this task. 我在JSP页面开发中还很陌生,对于如何解决此任务,我有以下疑问。
I have a JSP page that contains a JQuery accordion menu , something like it: 我有一个JSP页面 ,其中包含一个JQuery手风琴菜单 ,类似这样:
And this is the code that renders this accordion menu: 这是呈现此手风琴菜单的代码:
<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>
As you can see in the previous immage in the last column of the table putted inside the accordion header there are 3 icons that are implemented using JQuery buttons , these: 正如您在放在手风琴标题内的表的最后一列中的前一个图像中看到的那样,使用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>
Now what I have to do is submit a value (at this time even a fixed value, for esample: 1 for the first button, 2 for the second button and 3 for the third button) to the servlet that handle this view when a button is clicked. 现在,我要做的就是向一个处理此视图的servlet提交一个值(此时,对于esample,甚至是一个固定值:第一个按钮1个,第二个按钮2个,第三个按钮3个)被点击。
I think that I have to use a form that submit it in post. 我认为我必须使用在邮寄后提交的表格。 But what exactly have I to do?
但是我到底该怎么办? Searching online I founded this article: http://www.tutorialspoint.com/jsp/jsp_form_processing.htm
在线搜索我创建了这篇文章: http : //www.tutorialspoint.com/jsp/jsp_form_processing.htm
But in the previous tutorial show how to submit a form from an HTML page to a JSP but this is not what I want to do. 但是在上一教程中,展示了如何将HTML页面中的表单提交到JSP,但这不是我想要的。
How can I submit a form into a JSP to a servlet? 如何将表单提交到JSP中到servlet?
Tnx TNX
You can use Jquery $.post
ajax request to achive this: 您可以使用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.