Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get the button value from jsp to servlet

Tags:

jsp

servlets

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

like image 601
kawtousse Avatar asked May 26 '10 11:05

kawtousse


2 Answers

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.

like image 152
BalusC Avatar answered Sep 19 '22 14:09

BalusC


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);
like image 42
Ravindra Gullapalli Avatar answered Sep 16 '22 14:09

Ravindra Gullapalli