struts 入门

0. 请说明为啥报找不到result name=input

相当于自定mvc中的action层。
com.zking.framework

配置文件引入dtd不生效,无提示

1. 环境搭建
  1.1 jar
  1.2 web.xml
  1.3 struts.xml
      struts.xml(核心配置文件)

2. 开发
  2.1 Action
    2.1.1 不需要指定父类(ActionSupport)
    2.1.2 业务方法的定义
          public String xxx();//execute
    2.1.3 Action是多例模式(注:在spring中的配置中一定要注意)
          Action用来接收参数

  2.2 参数赋值
    2.2.1 Action中定义属性,并提供get/set方法
          userName, getUserName/setUserName

    2.2.2 ModelDriven
          返回实体,不能为null,不需要提供get/set方法
      
    2.2.3 ModelDriven返回实体和Action中属性重名,ModelDriven中优先级更高
          注:ognl,ActionContext学完就知道了

  2.3 与J2EE容器交互
    2.3.1 非注入
      2.3.1.2 耦合
              ServletActionContext

      2.3.1.2 解耦(建立使用解耦模式)
              ActionContext

   2.3.2 注入
      2.3.2.1 耦合
              作业:找出struts2中其它的几个注入接口(XxxAware)

      2.3.2.2 解耦
         

--src
--struts.xml(核心配置文件)
--struts.properties(全局属性文件)
3. 核心文件配置
  3.1 include    包含文件
      file
      
  3.2 package    包
      name        包名
      extends    继承
      namespace 虚拟路径
      abstract    通常用来被继承
  
  3.3 action    子控制器
      name:helloAction,helloAction_*
      class    全限定名
      method:execute,{1}


      注1:动态方法调用,新版本中已禁用,可自行开启或关闭
    
      注2:子控制器的访问路径:名称空间+"/"+子控制器名字_xxx+".action"
      

  3.4 result
      name
      type:dispatcher|redirect
      

猜你喜欢

转载自blog.csdn.net/lxxiaocaiji/article/details/83990606