java - check what button on form caused action -


i've got such form on page

<form action="toolbaraction.do" method="post">     <div id="toolbar"         class="ui-widget-header ui-corner-all ui-widget-content">         <input style="font-family: times new roman;" type="button" id="item0"             value="<fmt:message key='main'/>" /> <input             style="font-family: times new roman;" type="button" id="item1"             value="<fmt:message key='prices'/>" />         <c:choose>             <c:when test="${enterattr == false || enterattr == null }">                 <input style="font-family: times new roman;" type="submit"                     id="item2" value="<fmt:message key='book'/>" />             </c:when>             <c:when test="${enterattr == true }">                 <input style="font-family: times new roman;" type="submit"                     id="item2" value="<fmt:message key='check'/>" />             </c:when>         </c:choose>         <input style="font-family: times new roman;" type="submit" id="item3"             value="<fmt:message key='contacts'/>" /> <input             style="font-family: times new roman;" type="submit" id="item4"             value="<fmt:message key='service'/>" />     </div> </form> 

how check button pressed , caused toolbaraction? here exec method in toolbaraction classs. should parameters httpservletrequest?

public string exec(httpservletrequest req, httpservletresponse resp) {     // todo auto-generated method stub     return null; } 

the solution give same name attribute <input> elements.

<input name="submit" style="font-family: times new roman;" type="submit"                 id="item2" value="<fmt:message key='check'/>" /> 

since 1 submit button can pressed user each request, have single request parameter called submit. can retrieve like

string value = request.getparameter("submit"); 

where request httpservletrequest object. return value of getparameter value attribute of <input> element. can bunch of if checks see pressed.


Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -