如何从jsp中的超链接调用doPost()servlet [英] How to call doPost() servlet from a hyperlink in jsp
问题描述
如何从 jsp
调用 servlet
?但在这种情况下,我喜欢使用 doPost()
方法比 doGet()
。
How can I call a servlet
from jsp
? But in this case, I prefer to use doPost()
method than doGet()
.
这是我的代码:
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>
我打算调用一个servlet类(称为 ViewS
)从此页使用链接(编辑删除)。当我点击编辑并将值存储到数据库中时,我想在特定行中进行一些编辑。
I intend to call a servlet class (called ViewS
) from this page using link (edit n delete). 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.
因此,请有人帮助我。
我试过了使用< a href =/ ViewS?action = edit> edit< / a>
,但我知道这个调用 doGet
I've tried to use <a href="/ViewS?action=edit">edit</a>
, but I know this call doGet()
.
非常感谢您的帮助。
推荐答案
您需要在点击链接时调用javascript函数,并且您需要提交将生成HTTP POST的表单
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
function submitMyForm(){
document.forms["yourFormId"].submit();
}
或者你可以创建一个 AJAX调用您的servlet
这篇关于如何从jsp中的超链接调用doPost()servlet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!