zoukankan      html  css  js  c++  java
  • Struts2 (二)入门

    流程:

    01.Namespace空间的使用

       隔离同名类

      

    02.Acrtion创建多个自定义方法

     
    
     
    
    public class FirstAction extends ActionSupport {
    
    
        //用户自定义方法
    
        
        public String list(){
    
            return "list";
    
        }
    
    
        public String select(){
    
            return "select";
    
        }
    
    
    }

    Struts.xml

     

    03.动态方法调用

    Action

     

    Struts.xml

    版本高的struts2-core.jar 默认开启动态方法调用!
    <constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>
    <action name="dimaction" class="cn.happy.day02.DimAction">
        <result name="list">/day02/hello.jsp</result>
        <result name="select">/day02/update.jsp</result>
    </action>
    

      

    04.通配符

    Action

     

    Struts.xml

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

      

    05.esultType

    result type 默认值 dispatcher 转发到jsp页面
    chain 转发到Action
    redirect 重定向到jsp页面
    redirectAction 重定向到Action

    实例一:默认值dispatcher

      Action:

     

    Struts.xml:

    
    
    页面:
    
    
     

    实例二:redirect

    Action:

     

    Struts.xml:

     

    页面:

     

    实例三:chain

    Action

     

    Struts.xml

     

    页面

      

     

    实例四:redirectAction

    Action

     

    Struts.xml

     

    页面

     

    默认Action

    注:

    要在主的struts.xml中配置(自定义404页面)

    <default-action-ref name="noAction"></default-action-ref>
    
    <!--默认Action class=ActionSupport-->
    <action name="noAction" class="com.opensymphony.xwork2.ActionSupport">
        <result>/404.jsp</result>
    </action>
    

      

    
    
     
  • 相关阅读:
    如何解决无法成功git commit 和git push
    orleans 项目调试注意
    silo 主机 配置
    asp.net core 项目引用包版本问题
    C# async 方法怎么被正确的消费 (新篇)
    C# 虚方法 复习
    C# dynamic 适用场景进一步说明
    [MySQL]
    C# Subject 观察者模式
    C# 协变与逆变
  • 原文地址:https://www.cnblogs.com/1612ss/p/8472892.html
Copyright © 2011-2022 走看看