STRUTS2 Basic Learning (iii)-result and model-driven

Source: Internet
Author: User
Tags xslt

First, result

When the action finishes processing the user request, it returns a normal string, the entire normal string is a logical view name, STRUTS2 determines which result to respond to according to the logical view name, and processes the result using the <result> element configuration.

Local results: Configure <result> as the <action> child element.

Global Results: configures <result> as a child element of the <global-results> element.

Configuration <result> elements to specify two properties.

Name: This property specifies the configuration logical view name.

Type: Specifies the result type.

1. Global results

When the same result is used in more than one action, we should define result as a global result.

<package name= "user" extends= "struts-default" ><!--Configure global results--><global-results><result name= " Error ">/index.jsp</result></global-results><action name=" resultaction "class=" Com.kiwi.action.ResultAction "></action></package>

2. Result types
        <result-types> <result-type name= "Chain" class= "Com.opensymphony.xwork2.ActionChainResult"/&gt            ; <result-type name= "Dispatcher" class= "Org.apache.struts2.dispatcher.ServletDispatcherResult" default= "true"/            > <result-type name= "freemarker" class= "Org.apache.struts2.views.freemarker.FreemarkerResult"/> <result-type name= "Httpheader" class= "Org.apache.struts2.dispatcher.HttpHeaderResult"/> <result-t ype name= "redirect" class= "Org.apache.struts2.dispatcher.ServletRedirectResult"/> <result-type name= "Redi Rectaction "class=" Org.apache.struts2.dispatcher.ServletActionRedirectResult "/> <result-type name=" stream "class=" Org.apache.struts2.dispatcher.StreamResult "/> <result-type name=" Velocity "class=" org.apache.str Uts2.dispatcher.VelocityResult "/> <result-type name=" xslt "class=" Org.apache.struts2.views.xslt.XSLTResul T "/> < Result-type name= "plaintext" class= "Org.apache.struts2.dispatcher.PlainTextResult"/> </result-types> 

(1) Dispatcher

The request is forwarded to a page. The dispatcher result type is the most commonly used result type and is also the STRUTS2 default result type. The result type has a location parameter, which is the default parameter.

(2) redirect

The request is redirected to a page. The redirect result type redirects the response to another resource, rather than to the resource.

(3) Chain

The request is forwarded to another action.

The redirectaction result type accepts the following parameters:
ActionName: Specifies the name of the "destination" action. It is the default property.
namespace: The namespace used to specify the "destination" action. If this parameter is not configured, Struts will use the namespace where the current Action is located as the "destination" namespace.

If you want to forward to another package and the package has NAMESAPCE, you can write this.

<package name= "user" extends= "struts-default" ><action name= "Act1" class= "Com.kiwi.action.ResultAction" ><result name= "Success" type= "Chain" ><param name= "namespace" >/test</param><param name= " ActionName ">act2</param></result></action></package><package name=" Server " Namespace= "/test" extends= "Struts-default" ><action name= "Act2" ><result name= "Success" >/success.jsp </result></action></package>

(4) Redirectaction

Request redirect to another action, same as above.

(5) Stream

Download it for later.

(6) PlainText

The content is presented in plain text form.

STRUTS2 Basic Learning (iii)-result and model-driven

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.