Struts2 jump type result type = chain, dispatcher, redirect (redirect-act...

Source: Internet
Author: User

Dispatcher is the default jump type and is used to return a view Resource (such as JSP)
XML code:

<Result name = "success">/Main. jsp </result>
<Result name = "success">/Main. jsp </result>
The preceding statement uses two default statements. The complete statement is as follows:
<Result name = "success" type = "dispatcher">
<Param name = "location">/maini. jsp </param>
</Result>

For page forwarding, the page Jump process is always the same thread, and the data in the action is always saved in.
Location can only be a page, not another action (available type = "chain ).

 

The redirect type is used to redirect to a page, another action, or a URL. 
XML code:

<Result name = "success" type = "Redirect"> AAA. jsp </result>
<Result name = "success" type = "Redirect"> BBB. Action </result>
<Result name = "success" type = "Redirect"> www.baidu.com </result>

Disadvantage: Redirect resends an HTTP return code (SUCCESS) along with the returned page location to the Web server, which then generates a new HTTP request, A new thread is generated, and data stored in the thread where the original action is executed cannot be accessed.
Therefore, the result must contain the action data, So redirect is not a feasible method. Because the new HTTP request is processed in the new thread of the servlet container, no status exists in the actioncontext.

Solution:

(Method 1 ):
<Result name = "topic" type = "Redirect">/topicaction! Findtopics. do? Topicid =$ {topicid} </result>
(Method 2 ):
<Result name = "topic" type = "Redirect-action">
<Param name = "actionname"> findtopics </param>
<Param name = "topicid" >$ {topicid} </param>
</Result>

 

The redirect-action result type uses the actionmapper provided by actionmapperfactory to redirect the request to another action.
XML code:

<Result name = "Err" type = "Redirect-action">
<Param name = "actionname"> redirected action name </param>
<Param name = "namespace"> The namespace of the Redirection action </param>
</Result>
There is no difference in the use of redirect and redirect-action results, but they are written differently.

 

Chain is used to connect several related actions to complete a function.
XML code:

<Action name = "Step1" class = "test. step1action">
<Result name = "success" type = "chain"> step2.action </result>
</Action>
<Action name = "step2" class = "test. step2action">
<Result name = "success"> finish. jsp </result>
</Action>
Action in the chain belongs to the same HTTP request and shares an actioncontext


The plaintextj result type is used to display source code directly on the page.

XML code:

<Result name = "Err" type = "plaintext">
<Param name = "location"> location </param>
<Param name = "charset"> character specifications (such as GBK) </param>
</Result>

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.