Processing Method for HTML: Select multiple selections under struts

Source: Internet
Author: User
HTML: Select supports multiple choices. It is very easy to select multiple choices. The background accepts a string. What should I do when multiple choices are made?


1. To create a multi-choice select control, you need to add Code such as multiple = "true" to the attribute list, as shown below:
Code: select all
       
          <%

             for (i=0; i<userlist.size(); i++) {

               tmpstring = (String)userlist.get(i);

          %>

         
          <%

             }

          %>

       




2. After being defined as multiple, the field in the corresponding actionformbean should be defined as a string array. Note that arraylist or other things cannot be used, but only a string array can be used, as shown below:

Code: select all
       <!-- Create UG Queue Limit Action -->

       <action   path="/CreateUGQueueLimit"

                 type="com.jointforce.action.CreateUGQueueLimitAction"

                 name="CreateUGQueueLimitForm"

                 scope="request"

                 input="createugqueuelimit">

           <forward name="moduleunavailable" path="/jsp/joblimitunavailable.jsp"/>

           <forward name="createugqueuelimit" path="/jsp/createugqueuelimit.jsp"/>

           <forward name="success" path="/jsp/createugqueuelimitresult.jsp"/>

       </action>


      <!-- Create UG Queue Limit -->

      <form-bean name="CreateUGQueueLimitForm"

                 type="org.apache.struts.validator.DynaValidatorForm">

          <form-property name="userlist" type="java.lang.String[]"/>

          <form-property name="grouplist" type="java.lang.String[]"/>

          <form-property name="hostlist" type="java.lang.String[]"/>

      </form-bean>




Validation. XML is still in use:

Code: select all
        <form name="CreateUGQueueLimitForm">

            <field property="userlist"></field>

            <field property="hostlist"></field>

            <field property="grouplist"></field>

        </form>

 

Finally, in the action class, we can get the following:


String [] userlist = (string []) propertyutils. getproperty (form, "userlist ");

You can use a for loop to retrieve the stuff:

For (INT I = 0; I <userlist. length; I ++ ){
System. Out. println (userlist [I]);
}

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.