Redirect, redirect-action, and chain

Source: Internet
Author: User

The default result type of an action is dispatcher, which cannot be used directly to send requests between actions. Generally, the optional results include redirect, redirect-action, and chain. The first two are page jumps. That is to say, after a request is sent, the address in the address bar will be refreshed as the address of the requested action, while the chain will not update the address.

1. redirect-Action: "This result uses the actionmapper provided by actionmapperfactory to relocate the browser URL to call the specified action and (optional) namespace. this result is better than servletredirectresult. because you do not need to encode the URL into xwork. the mode provided by actionmapper configured in XML. this means that you can change the URL mode at any point without affecting your application. therefore, we strongly recommend that you use this result instead of the standard redirect result to relocate to an action. "--- webwork2.

2. Redirect: "Call the {@ link httpservletresponse # sendredirect (string) sendredirect} method to go to the specified position. The HTTP response is notified to allow the browser to jump directly to the specified location (generate a new request from the client ). the result will cause the newly executed action (including the Action instance and error messages in the action) to be lost and no longer available."

To put it simply, the two have the same thing: the address bar will change, and all the Request Parameters of the previous action will be lost. Of course, the attribute values of the action will also be lost. The path syntax is slightly different. When redirect-action requests the next action, there is no suffix. Action, while redirect is the same as the normal URL syntax. Redirect-Action supports Param to append request parameters, but this often causes servletactionredirectresult to report a warning that the xxx attribute cannot be found, probably because it cannot be identified as IOC injection, or is it because the URL is appended with the parameter? Although it is at the warn level, it is better to write it as XXX? A = x & B = y format, and & also need to write & amp; format, otherwise XML format error will be reported. (In addition, this URL form can also be used normally as the actionname value of PARAM)

3. chain: Like forward, it first shows that the address bar will not change, similar to dispatcher. At the same time, it features that it can share the data transmitted by forms in multiple actions. At the same time, according to the order of the Action chain, the attribute values of related actions are also passed, which means that you can get the attribute values of all previous actions (if there is a get method) on the final view page ). If multiple actions have the same attribute value, the subsequent actions will first use the data of the previous actions to assign values, and then perform logical processing and transmission.

It looks perfect, but it has a big problem. If the subsequent action needs to call the attribute value of the previous action, make sure that it has the same attribute value. Otherwise, you cannot receive the value of the previous action. He cannot get through additional parameters like redirect-action. He does not support XXX? A = x & B = y format. This will lead to a large number of coupling and invalid parameters, and it is difficult to pass parameters through the configuration file.

In addition, if an error occurs in the Action method before the action chain (for example, the haserror method of action returns true) or an exception occurs, it will force you to define the input result, including the subsequent actions. Otherwise, an error will be reported. In fact, even if the above conditions are met, he will not execute the following action, but directly jump to the input view of the following action. Unless the error action returns input and the type is "chain", and the method of the next action must be input, the subsequent method will not be executed, but will be directly located in the final physical view.

I think the application scope of chain has become very narrow. It is said that webwork2 does not advocate the use of chain, which has never been verified.

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.