Monday, March 1, 2010

Form submission with multiple text box with same name.

Input.Jsp:

<html:form action="/actionName" method=”post”>
Parameter1:<html:text property="parameter1"></html:text>
Parameter2:<html:text property ="Parameter1"> </html:text>
Parameter3:<html:text property ="Parameter1"> </html:text>

<html:submit value=”submit”></html:submit> | <html:reset value="Cancel" </html:reset >
</html:form>


 
ParameterForm.java
public class ParameterForm extends ActionForm {
String[] parameter1;

Setter, getter function of parameter1
}

ExampleAction.java
public class ExampleAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception{
ParameterForm parameterForm = (ParameterForm) form;
String[] parameter = parameterForm.getParameter1();

String parameter1 = parameter [0];
String parameter2 = parameter [1];
String parameter3 = parameter [2];

/* JDBC code to insert into database */
}
}