[英]How to call doPost() servlet from a hyperlink in jsp
How can I call a servlet
from jsp
? 如何从jsp
调用servlet
? But in this case, I prefer to use doPost()
method than doGet()
. 但在这种情况下,我更喜欢使用doPost()
方法而不是doGet()
。
this is my code: 这是我的代码:
view.jsp view.jsp的
<%@ page contentType="text/html;charset=UTF-8" language="java" import="DSIP.*" import="java.util.ArrayList" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>DSIP.View</title>
</head>
<body>
<jsp:useBean id="ipList" scope="application" class="DSIP.IPBeanMapper"/>
<jsp:useBean id="bean" scope="application" class="DSIP.IPBean"/>
<form name="form1" method="post" action="viewS">
<table width="" border="">
<tr bgcolor="#0099FF">
<td width="90"><div align="center">ip</div></td>
<td width="90"><div align="center">username</div></td>
<td width="90"><div align="center">password</div></td>
<td width="90"><div align="center">maxRetry</div></td>
<td width="90"><div align="center">action</div></td>
</tr>
<%
ArrayList<IPBean> list;
list = ipList.getIPList();
for (int i = 0; i < list.size(); i++){
bean = list.get(i);
%>
<tr>
<td><input name="ip" type="text" size="15" value="<%=list.get(i).getIp()%>"></td>
<td><input name="userName" type="text" size="15" value="<%=bean.getUserName()%>"></td>
<td><input name="password" type="text" size="15" value="<%=bean.getPassword()%>"></td>
<td><input name="maxRetry" type="text" size="15" value="<%=bean.getMaxRetry()%>"></td>
<td><a href="/ViewS?action=edit">edit</a> <a href="/ViewS?action=delete">delete</a>
</td>
</tr>
<%
}
%>
</table>
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>
I intend to call a servlet class (called ViewS
) from this page using link (edit n delete). 我打算使用link(edit n delete)从这个页面调用一个servlet类(称为ViewS
)。 I want to make some filed in a specific row being editable when I click edit and store the values into a database. 当我单击编辑并将值存储到数据库中时,我想让某些特定行中的某些字段可编辑。
and, I want to delete the record in database also record view in jsp when I cleck delete. 并且,我想删除数据库中的记录,当我cleck删除时,在jsp中记录视图。
So please, somebody help me. 所以,请有人帮助我。
I've tried to use <a href="/ViewS?action=edit">edit</a>
, but I know this call doGet()
. 我曾尝试使用<a href="/ViewS?action=edit">edit</a>
,但我知道这个调用doGet()
。
Thank you very much for helping me. 非常感谢你帮助我。
You need to call a javascript function on click of link and from javascript you need to submit the form that will generate a HTTP POST 您需要在点击链接时调用javascript函数,并且需要从javascript提交将生成HTTP POST的表单
function submitMyForm(){
document.forms["yourFormId"].submit();
}
Or you could make a AJAX call to your servlet 或者你可以对你的servlet进行AJAX调用
AJAX will be the best option for you. AJAX将是您的最佳选择。 Make an AJAX call from the onClick()
method of the <a>
从<a>
的onClick()
方法进行AJAX调用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.