struts入门

重点:
1、struts环境搭建
2、struts配置文件详细讲解
3、使用execute方法和动态调用方法
4.通过在jsp设置对象参数赋值的(重点单独的属性名和实体类的属性名值覆盖问题)

重点解析:

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

  1. 环境搭建
    1.1 导入关于struts的jar包
    1.2 配置web.xml文件
    1.3 配置struts.xml
    struts.xml(核心配置文件)

1.3.1注意一些主要的struts.xml中的constant的配置
struts入门

1.3.2如何在struts.xml中有提示
第一步:在xml中复制黑色圈起的代码
struts入门

第二步:选中项目,点击Window选择Preferences,输入xml选择xml Catalog ,点击User Specified Entries,界面如下:
struts入门

第三步:点击add,操作如下:

struts入门

第四步:完成以上步骤。点击 Apply and Close,刷新项目,在点击Validate,就可以在xml有提示了

  1. 开发
    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