I have this code in jsp page:
<select id="DateReport" style="width: 150px;">
<option value="1"> 1 </option>
<option value="2"> 2 </option>
<option value="3"> 3 </option>
</select>
How do I send the selected value to action class in Struts 1.2?
You need a property in your form MyForm
declared in your struts-config.xml
file:
<form-bean name="myForm" type="foo.MyForm" />
[...]
and associate it with your action
<action path="/myAction" name="myForm" type="foo.MyAction" scope="request">
In your form:
public class MyForm extends ActionForm {
private String myValue;
[....]
// Getters and setters for all attributes
}
Then in your JSP:
<html:form action="/myAction.do" method="post" >
[...]
<html:select styleId="DateReport" property='myValue' style="width: 150px;">
<html:option value="1"> 1 </html:option>
<html:option value="2"> 2 </html:option>
<html:option value="3"> 3 </html:option>
</html:select>
[...]
</html:form>
In your action's execute()
, you could get the value:
MyForm myForm = (MyForm) form;
String value = myForm.getMyValue();