Result types of Struts2 project construction (5)

illustrate

This article mainly explains the result type of Struts2

struts.xml section

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
        "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>
    <package name="login.action.LoginAction" extends="struts-default" namespace="/">
        <default-action-ref name="login"/>
        <action name="login" class="login.action.LoginAction" method="index">
            <result name="login" type="dispatcher">/index.jsp</result>
        </action>
        <action name="*_*_*" class="{1}.action.{2}Action" method="{3}">
            <result name="success" type="dispatcher">/login/login.jsp</result>
            <result name="login" type="dispatcher">/index.jsp</result>
        </action>
    </package>
</struts>

struts-default.xml involves type type (type attribute of result in struts.xml)

 <result-types>
            <result-type name="chain" class="com.opensymphony.xwork2.ActionChainResult"/>
            <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-type name="redirect" class="org.apache.struts2.dispatcher.ServletRedirectResult"/>
            <result-type name="redirectAction" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>
            <result-type name="stream" class="org.apache.struts2.dispatcher.StreamResult"/>
            <result-type name="velocity" class="org.apache.struts2.dispatcher.VelocityResult"/>
            <result-type name="xslt" class="org.apache.struts2.views.xslt.XSLTResult"/>
            <result-type name="plainText" class="org.apache.struts2.dispatcher.PlainTextResult" />
            <result-type name="postback" class="org.apache.struts2.dispatcher.PostbackResult" />
        </result-types>
  • chain Action chain processing result type, which represents a forwarding relationship, which is in a request. Under normal circumstances, when an action is processed, it will directly return to the page and output the result. But there is also a possibility that when an action is processed, it will directly jump to the next action for processing, and chain will be used at this time.
  • dispatcher default request forwarding result type
  • redirect redirect, redirect to a path information, the path information is not limited (not in a request)
  • redirectAction redirects to an action











I am a programmer. If you think it's well organized, please pay attention to your personal WeChat public account (scan it):

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326002327&siteId=291194637