You could easy do it by giving a name to the button, for example
<input name="action" type="submit" value="Delete user" />
now in the bean that in, your case form bean associated to the action, you should create a property
private String action;
public void setAction(String action){
this.action = action;
}
public String getAction(){
return action;
}
Struts 1 used commons beanutils to populate form bean. When you submit the form the field values are populated via setters. The button field is not exception from the rules. So, its value will also be set to the action
property. Then you could check it via
if (action != null && action.equals("Delete user")){
System.out.println("Button is: "+action);
}
The most natural Struts 1 way to identify and execute button events is to dispatch the message key value along with button. For example
<html:submit><bean:message key="button.delete"/></html:submit>
The "button.delete"
is a message resource key, should be in MessageResource.properties
file
button.delete = Delete user
The action should implement LookupDispatchAction
and override
@Override
public Map getKeyMethodMap() {
Map<String, String> map = new HashMap<String, String>();
map.put("button.delete", "delete");
return map;
}
then when action is executed it will dispatch to the method specified in the map
. In this example method delete
.