Create a dynamic struts form

Source: Internet
Author: User


1. How to create dynamic forms in struts (1) Step 1: create a simple registration page:

<Body> <form action = "/dynamicform/register. do? Flag = register "method =" Post "> U: <input type =" text "name =" name "/> <br/> P: <input type = "password" name = "password"/> <br/> <input type = "Submit" value = "registered user"/> </form> </body>

(2) Step 2: configure the dynamic form in the struts-config.xml file:

<? XML version = "1.0" encoding = "UTF-8"?> <! Doctype Struts-config public "-// Apache Software Foundation // DTD struts configuration 1.3 // en" "http://struts.apache.org/dtds/struts-config_1_3.dtd"> <Struts-config> <form-beans> <! -- Dynamic form creation is configured, not defined --> <! -- The type here is dynaactionform under the struts-core-1.3.8.jar in struts 1.3 libraries. class path --> <form-bean name = "userform" type = "org. apache. struts. action. dynaactionform "> <! -- The name here is the attribute in the form --> <form-property name = "name" type = "Java. lang. string "/> <form-property name =" password "type =" Java. lang. string "/> <form-property name =" name "type =" Java. lang. string "/> </form-bean> </form-beans> <global-limits/> <global-forwards/> <action-mappings> <action attribute =" userform" input = "/WEB-INF/register. JSP "name =" userform "parameter =" flag "Path ="/register "Scope =" request "type =" com. LC. struts. action. registeraction "cancellable =" true "> <forward name =" registerok "Path ="/WEB-INF/OK. JSP "/> </Action-mappings> <message-resources parameter =" com. LC. struts. applicationresources "/> </Struts-config>


(3) create an action to process the business logic: registeraction: 1. Create an action

Package COM. LC. struts. action; // export the package to public class registeraction extends dispatchaction {public actionforward register (actionmapping mapping, actionform form, httpservletrequest request, httpservletresponse response) {dynaactionform userform = (dynaactionform) Form; /** Method for retrieving data from a dynamic form */string name = userform. get ("name "). tostring (); string Password = userform. get ("password "). tostring (); system. out. println (name + "" + password + ""); Return Mapping. findforward ("registerok"); // page returned after successful completion }}


(4) The struts view is as follows:





Create a dynamic struts form

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.