Input.Jsp:
<html:form action="actionName" method="post">
parameter1:<html:text property="parameter1" />
parameter2:<html:text property="parameter2"/>
<html:submit></html:submit><html:reset></html:reset>
</html:form>
Struts-config.xml:
<form-bean>
<form-bean name="parameterForm" type="ParameterForm"/>
</form-bean>
<action-mappings>
<action
attribute="parameterForm"
name="parameterForm"
input="/input.jsp"
path="/actionName"
scope="request"
type="ExampleAction"
<forward name="success" path="/Success.jsp"/>
<forward name="failure" path="/Failure.jsp"/>
</action>
</action-mappings>
ParameterForm.java
public class ParameterForm extends ActionForm {
String parameter1;
String parameter2;
Setter, getter function of parameters
}
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 parameter1 = parameterForm.getParameter1();
String parameter2 = parameterForm.getParameter2();
/* JDBC code to insert into database */
}
}
No comments:
Post a Comment