Input of struts1 configuration file

Source: Internet
Author: User
<Action Path = "/* person" type = "cn. itcast. personaction" Scope = "request" input = "/{1}. jsp" parameter = "method">
<Forward name = "list" Path = "/WEB-INF/pages/list. jsp"/>
</Action>
Use wildcard characters, except that * is in the same position as {1.
The action I wrote inherits dispatchaction, parameter = Method
Assume that the ADD and edit methods () are available ()
When accessing the add method, use this address:/addperson. do? Method = add --> at this time, input is/Add. jsp

When accessing the Edit Method, use this:/editperson. do? Method = edit --> input is/edit. jsp.


Input = "/register. jsp" specifies the page on which formbean data is provided. Note: The purpose of this attribute is to easily jump back to the formbean input page when formbean verification fails, and display the verification failure information through the struts1 error message tag.


Matching the path and mode in struts Configuration
The action in struts configuration has a path attribute, which indicates the requested URI
In general, we need to specify a specific URI in the configuration file, such as Path = "/user/Add"
In some large applications, if we can develop a set of strict paths and their operation specifications, we can use the path pattern matching function of path to simplify the tedious compilation workload of struts configuration files.
Suppose there are the following specifications:
Path Matching specification example
All processing actions of the user object must be accessed in the following path:
/User/Add. Do-process operations related to user Addition
/User/Delete. Do-operations related to user Deletion
/User/update. Do-operations related to user updates
...
The JSP corresponding to all actions is as follows:
The following naming rules apply to the redirection page after successful (failed) operations:
/User/Add. Do->/user/add_success.jsp or/user/add_error.jsp
/User/Delete. Do->/user/delete_success.jsp or/user/delete_error.jsp
...
The following naming rules apply to the input interfaces of all operations:
Add operation->/user/add_input.jsp
Update operation->/user/update_input.jsp
...
Action configuration example
<Action
Path = "/user /*"
Type = "com. bjsxt. Struts. Web. Actions. useraction"
Name = "userform"
Parameter = "method"
>
<Forward name = "Index" Path = "/user/index. jsp"/>
<Forward name = "success" Path = "/user/{1} _ success. jsp"/>
<Forward name = "error" Path = "/user/{1} _ error. jsp"/>
<Forward name = "input" Path = "/user/{1} _ INPUT. jsp"/>
</Action>
Action configuration explanation
All/user /*. do requests are all processed by the useraction class. The useraction class inherits dispatchaction, which is distributed to different methods for processing based on the value of the passed method parameter.
Any method in the useraction class can return the actionforward with the index, success, error, and input names.
Depending on the Request Path, even if the same return code is called, The redirection will be different, for example:
/User/Add. do? Method = add request, which will be forwarded to the Add method of the useraction class for processing. Suppose it uses mapping. findforward ("success"); to return the success page. The actual JSP page is:/user/add_success.jsp.
And/user/Delete. do? Method = Delete request, which will be forwarded to the delete method of the useraction class for processing. Suppose it uses mapping. findforward ("success"); to return to the successful Deletion page, which will be switched to the actual JSP page:/user/delete_success.jsp, so, return pages with the same names for different URI requests will be different.
And/user/index. do request (or any other request, such as/user/ABCD. do or/user/test. do), because the method parameter is not passed, the unspecified method of useraction is called.

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.