zoukankan      html  css  js  c++  java
  • Struts2 基本的ResultType 【学习笔记】

    在struts2-core.jar/struts-default.xml中,我们可以找到关于result-type的一些配置信息,从中可以看出struts2组件默认为我们提供了这 
    些result-type 
           <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" /> 
                <!-- Deprecated name form scheduled for removal in Struts 2.1.0. The camelCase versions are preferred. See ww-1707 --> 
                <result-type name="redirect-action" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/> 
                <result-type name="plaintext" class="org.apache.struts2.dispatcher.PlainTextResult" /> 
            </result-types>

    其中

    dispatcher     返回jsp

    struts.xml

    <action name="*_*" class="cn.happy.action.{1}" method="{2}">
        <result name="{2}">
                    /{1}/{2}.jsp
            </result>
    </action>        

    默认的模式 无需特殊指定result节点中的type属性

    chain    实现从一个Action方法A跳转到另一个方法B

    struts.xml

    <!-- chain 转发到另一个Action-->
            <action name="userAction" class="sword.action.UserAction" method="list">
                <result name="list" type="chain">
                    <param name="actionName">userActionDel</param>
                    <param name="namespace">/</param>
                </result>
            </action>
    
            <action name="userActionDel" class="sword.action.UserAction" method="del">
                <result name="del">
                    /del.jsp
                </result>
            </action>

    Action

    public class LogAction extends ActionSupport {
        private String uname;
        private String pwd;
    
        public String log() throws Exception {
    
            return "log";
        }

    jsp

    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <title>Title</title>
    </head>
    <body>
        这是del
    </body>
    </html>

    最后地址栏的地址没有变化 请求到了list方法后 转发到了del方法 最后回到了jsp页面

  • 相关阅读:
    再也不用为word 中表达式的上标和下标发愁了
    创建链接
    ps钢笔工具隐藏的知识。
    学Ps个人遇到的小细节
    新手琢磨ps,学问深着呢。。
    数据库2012终于知道数据库攻击注入参数
    想脱离鼠标,不想要鼠标就只想用键盘完成所有编程,你说可能吗?
    vs2013中的快捷键
    如何在C/C++中动态分配二维数组【转载】
    转载:C++的那些事:表达式与语句
  • 原文地址:https://www.cnblogs.com/swordtm/p/6491428.html
Copyright © 2011-2022 走看看