how to get the button value from jsp to servlet in jsp:
<input type=button name=bt value=gi onclick="document.frm.submit();"></input>
and in servlet like that:
String gi =request.getParameter("bt");
System.out.print("button value" +gi);
result=null
thanks
Rather use <input type="submit">
.
<input type="submit" name="bt" value="gi">
Its name/value pair will be sent to the server side as well:
String bt = request.getParameter("bt"); // gi
No need for JavaScript hacks/workarounds here. It would also break your application in case that the client has JavaScript disabled.
Take a hidden variable inside form and use it like this.
<form name="frm" method="post" action="">
<input type="hidden" name="hdnbt" />
<input type="button" name="bt" value="gi" onclick="{document.frm.hdnbt.value=this.value;document.frm.submit();}" />
</form>
Now, in the servlet,
String gi =request.getParameter("hdnbt");
System.out.print("button value" +gi);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With