Struts2 processing result (2) -- processing result type, struts2 type

Source: Internet
Author: User

Struts2 processing result (2) -- processing result type, struts2 type

Struts2 processing result (2)

-- Processing result type

1. Supported result types created in Struts2:

  The type attribute in the <result> element determines the result type.

Chain: The result type of Action chain processing;

Dispatcher: specifies that JSP is used as the result type of the view resource;

Freemarker: Specifies the result type of the view resource using the FreeMarker template;

Httpheader: The result type that controls special HTTP behaviors;

Redirect: The result type of the jump to another URL;

RedirectAction: Jump to the result type of another Action;

Stream: returns an InputStream to the browser;

PlainText: displays the source code result type of a page;

...

2. plainText

 Displays the source code of the actual view resource. In essence, this view resource file is treated as a common text file, so the source code of this view resource is displayed.

Example:

 

<struts>    <constant name="struts.enable.DynamicMethodInvocation" value="false" />    <constant name="struts.devMode" value="true" />    <package name="package_a" extends="struts-default">        <action name="test1" class="testAction.Test1Action">            <result type="plainText">                <param name="location">welcome.jsp</param>                <param name="charSet">UTF-8</param>            </result>        </action>    </package></struts>

 

3. redirect

  In contrast to the dispatcher type, the dispatcher type forwards requests to the specified JSP page, while redirect redirects requests to the new view resource. redirect will lose all request parameters, attributes, and Action instances.

Example:

<Struts> <constant name = "struts. enable. dynamicMethodInvocation "value =" false "/> <constant name =" struts. devMode "value =" true "/> <package name =" package_a "extends =" struts-default "> <action name =" test1 "class =" testAction. test1Action "> <! -- Action redirects to this address after processing the request --> <result type = "redirect"> welcome. jsp </result> </action> </package> </struts>

 

3. redirectAction

 

  Compared with the redirect type, the redirect type is redirected to a view resource, while the redirectAction is redirected to another Action. The processing result, request parameters, and attributes of the previous Action are all lost.

Example:

<Struts> <constant name = "struts. enable. dynamicMethodInvocation "value =" false "/> <constant name =" struts. devMode "value =" true "/> <package name =" package_a "extends =" struts-default "> <action name =" test1 "class =" testAction. test1Action "> <! -- This result type is redirectAction, and is redirected to an Action whose namespace is/B and whose name is package_ B --> <result type = "redirectAction"> <! -- Specify the redirected Action --> <param name = "actionName"> test2 </param> <! -- Specify the namespace of the Action --> <param name = "namespace">/B </param> </result> </action> </package> <package name =" package_ B "extends =" struts-default "namespace ="/B "> <action name =" test2 "class =" testAction. test2Action "> <result name =" error "> error. jsp </result> </action> </package> </struts>

 

 

 

 

 

 

  

 

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.