tags:

views:

101

answers:

2

hi, 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

+1  A: 

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);
RaviG
+1  A: 

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.

BalusC