這可能是一個重複的問題,我很抱歉。我有一個jsp頁面,其中有一些按鈕。每個按鈕都有自己的servlet來調用。我想知道是否有任何方法可以在不使用表單的情況下調用這些servlet,因爲用戶可以選擇給定的3個功能之一。我還需要從jsp頁面傳遞一個值給我所調用的servlet。如何從jsp中調用servlet而不使用表格
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Configurations</title>
<script type="text/javascript">
function runConfiguration(){
var config=${dataValues.get(0)};
//call servlet
}
function editConfiguration(){
var config=${dataValues.get(0)};
//call servlet
}
function deleteConfiguration(){
var config=${dataValues.get(0)};
//call servlet
}
</script>
</head>
<body>
<%
String[] label={"Master Port","Baud Rate","Char Size","Stop Bits","Parity","RTU Port","Baud Rate","Char Size","Stop Bits", "Parity"};
int i=0;
%>
<br>
<br>
<br>
<table align="center" border="1">
<td><div align="center" style="background-color: goldenrod;"><b> ${dataValues.get(0)}</b></div>
<table width="210" align="left" border="1">
<td bgcolor="goldenrod"><b> Header1 </b></td>
<c:forEach var="data" begin="1" end="5" items="${dataValues}" varStatus="status">
<tr>
<td><%=label[i++]%>: ${data}</td>
</tr>
</c:forEach>
</table>
<table width="210" align="left" border="1">
<td bgcolor="goldenrod"><b> Header2 </b></td>
<c:forEach var="data" begin="6" end="10" items="${dataValues}" varStatus="status">
<tr>
<td><%=label[i++]%>: ${data}</td>
</tr>
</c:forEach>
</table>
</td>
</table>
<c:choose>
<c:when test="${dataValues.get(11)==1}">
<p align="center"><b><i>This configuration is already running</i></b></p>
<p align="center">
<input type="button" value="stop" onclick="StopConfiguration"/>
</p>
</c:when>
<c:otherwise>
<p align="center"><b><i>This configuration is currently NOT running</i></b></p>
<p align="center">
<button type="button" onclick="runConfiguration()">Run</button>
<button type="button" onclick="editConfiguration()">Edit</button>
<button type="button" onclick="deleteConfiguration()">Delete</button>
</p>
</c:otherwise>
</c:choose>
</body>
</html>
+1有用和翔實 – 2013-01-16 05:11:09