zoukankan      html  css  js  c++  java
  • struts2笔记08-初识ActionSupport

    1、配置一个最简单的action

    <action name="simple-action">
    	<result>/simple.jsp</result>
    </action>
    

     没有class, 没有method,result也没有name属性,但是可以访问成功!肯定是struts2背后偷偷帮我们干了些什么。

    2、struts-default.xml

    /struts2-core-2.3.28.jar/struts-default.xml

    <default-class-ref class="com.opensymphony.xwork2.ActionSupport" />
    

    这里配置了一个默认class,就是ActionSupport.

    3、ActionSupport类

       查看源代码

    public class ActionSupport implements Action, Validateable, ValidationAware, TextProvider, LocaleProvider, Serializable
    

      查看Action接口

    package com.opensymphony.xwork2;
    
    public interface Action {
    
        public static final String SUCCESS = "success";
      
        public static final String NONE = "none";
    
        public static final String ERROR = "error";
    
        public static final String INPUT = "input";
     
        public static final String LOGIN = "login";
    
        public String execute() throws Exception;
    }
    

     这个Action接口,简单至极,再看ActionSupport实现的execute源码

        public String execute() throws Exception {
            return SUCCESS;
        }
    

      

    struts2默认就给我们做了这些事,如果我们配置了一个action,没有配置class,就用它了,默认method为execute,result默认name为success. 

  • 相关阅读:
    接口
    多态
    封装
    初识继承
    对象的行为
    类、对象、包
    Java方法
    winform 报表的基本使用
    oracle配合C#的使用
    sql面试语句与后台调用js提示语句
  • 原文地址:https://www.cnblogs.com/sdnu/p/5352783.html
Copyright © 2011-2022 走看看