请问在jsp页面有两个按钮,在后台java程序中如何判断用户点击的是哪个按钮?例如:

<form action="apply.do?method=sp" method="post" id="f1" name="f1">
申请人:<input type="text" name=time ><br/>
地点:<input type="text" name=place><br/>
目的:<input type="text" name=target><br/>
<input type="button" name="agree" value="同意" onclick="examine()"/>
<input type="button" name="disagree" value="不同意" onclick="examine()">
</form>

JS函数,用于点击按钮提交表单:
function examine(){
if(confirm("确定?")){
document.f1.submit();
}
}
使用的sprin mvc框架,如何在后台,也就是action所对应的java函数方法中判断用户是点击的哪个按钮?

在<form>标签内加一个隐藏字段
<input type="hidden" name="type" id="type"/>
function examine(type){
document.getElementById("type").value=type;
if(confirm("确定?")){
document.f1.submit();
}
<input type="button" name="agree" value="同意" onclick="examine('1')"/>
<input type="button" name="disagree" value="不同意" onclick="examine('0')">

在action中接收type的值就可以知道是同意还是不同意
温馨提示:内容为网友见解,仅供参考
第1个回答  2013-02-05
既然你的连个按钮都在表单中一块提交到后台了,二你的来那个按钮都设置了两个不同的value值了,那你在后台获取出来,这两个name所对应的值进行一下判断一下不就行了。追问

怎样从后台获取按钮的值?用requset.getParameter("").equals("")判断不行。
请教具体代码
谢谢

第2个回答  2013-02-04
你这个是两个都会提交的,写两个function吧
第3个回答  2013-02-04
加个参数啊,1代表同意,0代表不同意
相似回答