Struts的Dynamic Form

1 Why there is Dynamic Form
The dynamic form can be used more flexibly. In some cases where the number and type of the form are uncertain, the dynamic form can be used to solve the problem.
 
The difference between a dynamic form and a normal form
1 normal form
First define a form class, and then configure it.
2 Dynamic forms
It is completely created by the reflection mechanism, so there is no need to define the form class, just configure it directly.
Three Quick Starts
1. If you configure a dynamic form
  
<form-beans >
        <form-bean name="userForm1" type="org.apache.struts.action.DynaActionForm" >
                <!-- The properties of this form are configured -->
                <form-property name="username" type="java.lang.String" />
                <form-property name="password" type="java.lang.String" />
                <form-property name="email" type="java.lang.String" />
    </form-bean>
  </form-beans>
 
2. How to retrieve data
public ActionForward register(ActionMapping mapping, ActionForm form,
                        HttpServletRequest request, HttpServletResponse response) {
                DynaActionForm userForm1 = (DynaActionForm) form;// TODO Auto-generated method stub
                // get data from dynamic form
                String name=userForm1.get("username").toString();
                String password=userForm1.get("password").toString();
                String email=userForm1.get("email").toString();
                System.out.println(name+" "+password+" "+email);
                return mapping.findForward("registerok");
                
        }
 
 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326610236&siteId=291194637