我有一个带有多个提交按钮的 jsp 页面。现在,如果我想根据用户单击的提交按钮(即基于某些条件)将参数转发到 jsp 文件。如何做到这一点?
我正在考虑使用 jsp:forward 来传递 jsp:params (在调用者页面中定义)。但是,我无法弄清楚如何使参数名称有条件。
有人可以建议如何实施吗?
任何帮助将不胜感激。
谢谢,
索姆纳特
如果您不使用 servlet,这样的事情怎么样?这是与JSTL
.
<c:choose>
<c:when test="${param.button1}">
<jsp: forward page="page1.jsp">
<jsp: param name="myParam" value="whatever1"/>
</jsp: forward>
</c:when>
<c:when test="${param.button2}">
<jsp: forward page="page2.jsp">
<jsp: param name="myParam" value="whatever2"/>
</jsp: forward>
</c:when>
</c:choose>
<form method="POST" action="">
<input type="submit" name="button1" value="button1" />
<input type="submit" name="button2" value="button2" />
</form>
您可以为每个提交按钮赋予不同的值。见
http://www.chami.com/tips/internet/042599I.html
让每个提交按钮成为表单中的一个按钮,然后在单击它时调用一个确定它来自何处的 javascript 函数,或者让该函数是唯一的,然后将该值作为参数转发给 servlet。