[Web Development Study Notes] Structs2 Result Study Notes (1) Brief Introduction

Source: Internet
Author: User

[Web Development Study Notes] Structs2 Result Study Notes (1) Brief Introduction
Structs2 Result Study Notes (1) Brief Introduction Question 1

<struts>    <constant name="struts.devMode" value="true" />    <package name="resultTypes" namespace="/r" extends="struts-default">    <action name="r1">    <result type="dispatcher">/r1.jsp</result>    </action>        <action name="r2">    <result type="redirect">/r2.jsp</result>    </action>        <action name="r3">    <result type="chain">r1</result>    </action>        <action name="r4">    <result type="redirectAction">r2</result>    </action>        </package></struts>
Dispatcher-forward uses the server to jump to the server and display the action

Redirect-redirect to jsp

Chain server jump

RedirectAction
Question 2 chain jump-> jump from an action to another action in the package:
<package name="public" extends="struts-default">    <!-- Chain creatAccount to login, using the default parameter -->    <action name="createAccount" class="...">        <result type="chain">login</result>    </action>    <action name="login" class="...">        <!-- Chain to another namespace -->        <result type="chain">            <param name="actionName">dashboard</param>            <param name="namespace">/secure</param>        </result>    </action></package><package name="secure" extends="struts-default" namespace="/secure">    <action name="dashboard" class="...">        <result>dashboard.jsp</result>    </action></package>
The example shows that the actionName and namespace parameters are configured for the chain;
For more information, see the documentation in struts-2.1.6/docs/chain-result.html.
Question 3: global Result
// Front-end htm <body> Result type <ol> <li> <a href = "user/user? Type = 1 "> return success </a> </li> <a href =" user/user? Type = 2 "> error returned </a> </li> <a href =" user/user? Type = 3 "> return global result </a> </li> <a href =" admin/admin "> admin, inherit user package </a> </li> </ol> </body>
//struct.xml<struts>    <constant name="struts.devMode" value="true" />    <package name="user" namespace="/user" extends="struts-default">            <global-results>    <result name="mainpage">/main.jsp</result>    </global-results>        <action name="index">    <result>/index.jsp</result>    </action>        <action name="user" class="com.struts2.user.action.UserAction">    <result>/user_success.jsp</result>    <result name="error">/user_error.jsp</result>    </action>        </package>        <package name="admin" namespace="/admin" extends="user">    <action name="admin" class="com.struts2.user.action.AdminAction">    <result>/admin.jsp</result>    </action>    </package></struts>
// Class package // AdminActionpackage com. struts2.user. action; import com. opensymphony. xwork2.ActionSupport; public class AdminAction extends ActionSupport {@ Overridepublic String execute () throws Exception {return "mainpage" ;}}// UserActionpackage com. struts2.user. action; import com. opensymphony. xwork2.ActionSupport; public class UserAction extends ActionSupport {private int type; public int getType () {return type;} public void setType (int type) {this. type = type ;}@ Overridepublic String execute () throws Exception {if (type = 1) return "success"; else if (type = 2) return "error "; else return "mainpage ";}}
Analysis 1
    <package name="user" namespace="/user" extends="struts-default">            <global-results>    <result name="mainpage">/main.jsp</result>    </global-results>        <action name="index">    <result>/index.jsp</result>    </action>        <action name="user" class="com.struts2.user.action.UserAction">    <result>/user_success.jsp</result>    <result name="error">/user_error.jsp</result>    </action>        </package>
In this configuration file, when the result is success, call user_success.jsp. If the result is error, call
/User_error.jsp. In all other cases, the result is configured as mainpage. This result set can be shared.
Analysis 2
    <package name="admin" namespace="/admin" extends="user">    <action name="admin" class="com.struts2.user.action.AdminAction">    <result>/admin.jsp</result>    </action>    </package>
Extends is used to inherit the configuration information from another package. It is used to process projects in modules. Each module has public configuration information, in this way, the public configuration information can be defined as <global-results>, and then inherited by each module to simplify processing. It seems like the inheritance relationship with c ++/java!
Problem 4: struct-default parsing source file in ReferencedLibraries/WebRoot/WEB-INF/lib/struts2-core-2.1.6.jar/struct-default.xml
    <package name="struts-default" abstract="true">
The Interceptor is defined by default.
<default-interceptor-ref name="defaultStack"/><default-class-ref class="com.opensymphony.xwork2.ActionSupport" />
Conclusion: The configuration is complex and does not need to be changed.

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.