Struts Development Practice - Practical Tips (on)

zhaozj2021-02-16  58

First, Struts uses tips (Mainly from "struts in action)

1. Use Array in ActionForm to match repetitive variables. For example, when using MultiBox, the Array can be defined in the Form.

2. Use to display the total number of records of Collection.

EG: . If there is two records, 2 is displayed.

3. Display the cyclic serial number mark:

4. Use to check if the object exists. Check if the properties exist in .

5. Relatively stable drop-down list data sets use scope = "application". (This method has always been used, but it is still not clear that it will be used directly when the system is logged in, and it can be used directly).

6. Use the to set the path to the CSS and JS files. (This does not see any difference with direct use).

7. JavaScript interacts with the FORM value: This is very frequent

EG:

9. In the page using JavaScript, the names of the two FORM objects cannot appear. Especially submit buttons, we often do not write Name, the default Name is Submit, which is wrong if there is an onclick event trigger.

10. Several ActionForm public properties can define a subclass in the ActionForm.

EG: Class BasicInfo Implement Serializable {};

It is necessary to define BasicInfo BasicInfo = New BasicInfo () in ActionForm;

Property = "BasicInfo.a" in the JSP page

Second, upload documents

1. You need to define the FormFile type field in ActionForm. EG: Formfile MyPhoto

2. In the JSP page

3. An error may occur after Submit: No Multipart Request Date Sent

solution:

1. Set the Redirect tree in struts-config.xml to TRUE.

2. If it is a jump with parameters, use the following method:

ActionForward Forward = mapping.forward ("surpass"); stringbuffer bf = new stringbuffer (forward.getpath ());

bf.append ("? id = 1"); // parameter

Return New ActionForward (bf.tostring (), true);


New Post(0)