struts2概要


2. Struts1 怎样实现MVC?
    2.1 核心控制器
         2.1.1 核心控制器  ActionServlet
        2.1.2 业务逻辑控制器 Action
     2.2 提供了标签,简化V的编写
     2.3 表现层框架对M没有支持 
3. Struts1 有什么样的缺点?  对servlet的简单封装
     3.1 支持的表现层技术单一。
     3.2 与servlet api严重耦合 execute()
     3.3 代码严重依赖于struts1 的API,属于侵入式设计
4. webwork:opensymphony-- > XWork   AOP 
5. 如何在项目中使用Struts2
     5.1 jar (7 + 2)
     5.2 log4j.properties
     5.3 提供好配置文件 struts.xml src
     5.4 web.xml
     5.5 编写业务逻辑控制器
     5.6 配置在struts.xml
6.Struts2的Action非单例 
7. 获得表单参数
     7.1 属性驱动
     7.2 模型驱动, 提供一个特定的JavaBean,用它来收集表单参数以及传递给下个页面的信息
            7.2.1 让Action implements ModelDriven
            7.2.2 自己创建模型的实例
            7.2.3 getModel()  返回创建的模型的实例
            7.2.4 model.uname   uname
     7.3 扩展的属性驱动:本质上还是属性驱动, 属性不是简单属性,而是JavaBean
           7.3.1 不需要自己实例化  private LogInfo info;
           7.3.2 提供对应的get/set方法
           7.3.3 提交页面<input name="info.email">
           7.3.4 显示页面: ${info.uname }
8. 如何传递给下个页面信息
    8.1 通过实例变量进行传递
    8.2 通过Servlet API
9. 在页面如何访问Action传入的信息 , ActionContext <s:debug/>
       9.1 Value Stack
            9.1.1 el requestScope ${info} ${requestScope.info}
            9.1.2 struts2的标签 <s:property />
      9.2 Stack Context
            9.2.1 el 是哪个就用哪个作用域
            9.2.2 struts2的标签 <s:property value="#"/>
10. Configuration Files
      10.1 web.xml(可以提供参数,但不会这么来做)
      10.2 struts.xml
      10.3 struts.properties  -- > 用来覆盖defuault.properties
      10.4 struts-default.xml (package : 4)
      10.5 velocity.properties
      10.6 struts-default.vm
11. Action
      11.1 POJO
      11.2 implements Action
      11.3 extends ActionSupport(提供了校验国际化的方法,可以简化Action的编写) (*)     
12. Package
      12.1 解决命名冲突 & 便于管理
      12.2 name给包起一个名字,在继承的时候用的上
      12.3 extends 继承哪一个, 可以使自定义也可以说struts-default
      12.4 namespace:  
13. 如何在一个Action中包含多个处理单元   public String  ()
       13.1 动态方法调用
          ### Set this to false if you wish to disable implicit dynamic method invocation
          ### via the URL request. This includes URLs like foo!bar.action, as well as params
          ### like method:bar (but not action:foo). 
          ### An alternative to implicit dynamic method invocation is to use wildcard
          ### mappings, such as <action name="*/*" method="{2}" class="actions.{1}">
      13.2 把一个物理上的Action映射为多个逻辑上的Action<action method="">
      13.3 通配符 
            13.3.1 约定优先 Action method jsp
            13.3.2 先找严格匹配的,没有严格匹配的,才考虑统配
           13.3.3 只要是统配,按照从上到下的顺序,第一个可以统配成功的被使用
           13.3.4 如果有<action name="*" >,必须放到最后面
           13.3.5 <default-action-ref name="index" />在包内找不到特定的Action的时候,会使用,如果统配成功,也认为找到了,default-action-ref无意义。
14. 访问Servlet API   
     14.1 拿到Map的Servlet API(不包括response)对象
           14.1.1 依赖于特定API (*)
                   ActionContext.getContext().getSession()
                  (Map<String, Object>) ActionContext.getContext().get("request")) 基本用不上
                  ActionContext.getContext().getApplication()
             14.1.2 依赖于注入(拦截器)
                   import org.apache.struts2.interceptor.ApplicationAware;
                   import org.apache.struts2.interceptor.RequestAware;
                   import org.apache.struts2.interceptor.SessionAware;
      14.2 拿到真实类型的Servlet API  -- > 最好用el
           14.2.1 依赖于特定API (*)
                     ServletActionContext
          14.2.2 依赖于注入(拦截器)
                      import org.apache.struts2.interceptor.ServletRequestAware;
                      import org.apache.struts2.interceptor.ServletResponseAware;
                      import org.apache.struts2.util.ServletContextAware;
15. OGNL: Object Graph Navigation Language 类似于el ,应用在Struts2的标签里面 <s:property value="ognl"/> 
16. 简单的校验(——)
17. Result
       17.1 范围: result(本Action使用)  vs   global-results(本包的所有Action使用) ,局部优先
       17.2 类型: 用于指明当前转向什么样的资源
             17.2.1 默认的类型
                  <result-type name="chain" class="com.opensymphony.xwork2.ActionChainResult"/> Action的链式调用
                  <result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/>
                 <result-type name="redirect" class="org.apache.struts2.dispatcher.ServletRedirectResult"/>
                 <result-type name="redirectAction" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>
                 两个Action之间如何传递信息:
                 chain:ActionContext.getContext().put("uid", id);
                 redirectAction:Session  url :<result type="redirectAction">emailAction?uid=%{id}</result>
            17.2.2 可以扩展:<result-type name="chart" class="org.apache.struts2.dispatcher.ChartResult">
            17.2.3 跳转到其它包的Action
            <result type="redirectAction">
                <param name="actionName">HelloWorld</param>
                <param name="namespace">/example</param>
            </result>
       17.3 定义自己的result-type
            17.3.1 extends StrutsResultSupport
            17.3.2 重写doExecute(String finalLocation, ActionInvocation invocation),配置的路径
18. 声明式异常处理 dao -- > service  - > Action (统一异常处理)  try { }catch() {}catch() {}
 <exception-mapping result="result的name" exception="异常的类型"></exception-mapping>
        18.1 异常是有继承关系: 先找精确的
        18.2 既有局部(本Action使用)又有global-exception-mappings(本包所有Action共享)
      先找精确,同等级别下,局部优先
        18.3 global-exception-mappings最好转向到global-results
        18.4 应该怎么去用: global-exception-mappings: <exception-mapping result="error" exception="java.lang.Exception"></exception-mapping>Action所特定关心的一些:往往和用户的输入相关, 局部 
19. 

         19.1 ActionContext  

         19.2 拦截器的顺序问题  
20. 编写自己的拦截器
         20.1 extends AbstractInterceptor
         20.2 implements Interceptor
         20.3 配置 struts.xml  <interceptors> </interceptors>
21. 文件上传(如何给拦截器配置参数)
       21.1 method="post" enctype="multipart/form-data"
       21.2 Action private File repo;private String repoFileName;private String repoContentType;
       21.3 struts.multipart.maxSize=20971520  一次请求最大的大小,如果不满足这个条件,错误信息来自于common-fileupload

22. token(如何使用额外的拦截器)

23. 对现有拦截器进行修改
24. 标签
         24.1 Generic Tags
               24.1.1  Control Tags
               24.1.2  Data Tags
         24.2 UI Tags(主题 xhtml)
              24.2.1 Form Tags
              24.2.2 Non-Form UI Tags
              24.2.3 Ajax Tags(dojo)
         type: object 默认理解为ognl  如果希望强制按照字符串理解‘’ 
         String 默认理解为字符串, 如果希望强制按照ognl理解
          24.3 修改现有主题 src  -- > template  -- > simple -- > 哪个不适合,单独提供
          24.4 定义新的主题 src  -- > template ---> abc(主题的名字)通过 theme.properties指明继承simple   
25. 校验: 在真正执行处理单元之前,对用户提交的信息进行基本校验, 如果满足业务要求,执行处理单元,否则转向到由input指向的页面。
         25.1 客户端校验(防止用户的误操作) vs 服务器端校验(防止恶意攻击)
         25.2 服务器端校验: 手工校验(validate  validateXxx)  配置校验(xml-->描述业务规则)
         25.3 手工校验:  在Action中重写 validate(不管处理哪个处理单元,都会执行),  validateXxx
         25.4  配置校验: 提供xml-->描述校验规则
             ActionName-validation.xml  -- > validate
26. 国际化
      26.1 资源文件的命名  baseName_语言_国家.properties   baseName.properties
      26.2 ResourceBundle bundle = ResourceBundle.getBundle("msg", Locale.US);
      String message =  bundle.getString("key1");
      System.out.println(MessageFormat.format(message, "小张"));
 26.3 Jsp: <s:property value="%{getText("")}"/> ,但不建议使用;
           <s:i18n name="com/pk/conf/user"><s:text/></s:i18n>
 26.4 Action: getText("key")   使用的资源文件最好是Action级别的或者是package级别
 26.5 资源文件有级别
  26.5.1 全局资源文件 <constant name="struts.custom.i18n.resources" value="msg"></constant>
  26.5.2 package级别: baseName必须是package,可以被本包及子包所有Action所共享
  26.5.3 Action级别:baseName必须和类名一致,同时放在同一个目录下,可以被本Action及子类使用
  26.5.4 查找顺序:Action级别  -- 》 package级别  --》 全局资源文件 
27. 类型转换
XWork will automatically handle the most common type conversion for you. This includes support for converting to and from Strings for each of the following:

String
boolean / Boolean
char / Character
int / Integer, float / Float, long / Long, double / Double
dates - uses the SHORT format for the Locale associated with the current request
arrays - assuming the individual strings can be coverted to the individual items
collections - if not object type can be determined, it is assumed to be a String and a new ArrayList is created
28. 和spring的整合
 28.1 Autowiring: Action是struts2自己管理
 默认安装name进行自动装配: struts.objectFactory.spring.autoWire = name
  28.1.1 注解 Action: 不用加Controller
 28.2 Initializing Actions from Spring: Action交给spring管理
  28.2.1 在spring配置Action: scope="prototype"
  28.2.2 修改struts.xml <action class="对应的bean的id">
  28.2.3 注解 Action : @Controller @Scope("prototype") service: @Service
 28.3  When an object is to be created, it uses the class attribute in the Struts
 configuration to correspond to the id attribute in the Spring configuration.
 If not found, the class will try to be created as usual, then be autowired by Spring.
 By default, the framework will at least try to use Spring to create all its objects.
 If the object cannot be created by Spring,
 then the framework will create the object itself. 
 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值