1. 框架是什么,框架有什么作用
      1. 框架 实现部分功能的代码.
      2. 作用 控制请求和响应.
    2. 相对于WEB项目的执行流程
    3. struts2项目搭建流程
      1. 配置web.xml 配置前端控制器[核心控制器] ---一个filter.
        1. 包名:org.apache.struts2.dispatcher.ng.filter.
        2. 类名:StrutsPrepareAndExecuteFilter
        3.   <filter>
          <filter-name>struts2</filter-name>
          <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
          </filter> <filter-mapping>
          <filter-name>struts2</filter-name>
          <url-pattern>/*</url-pattern>
          </filter-mapping>
      2. 配置struts.xml --struts2框架配置文件
        1. 作用:控制struts2框架执行的流程
        2. 文件名称:struts.xml
        3. 路径:src
        4. struts配置文件的加载顺序
          1. init_DefaultProperties(); // [1] ---------- org/apache/struts2/default.properties
          2. init_TraditionalXmlConfigurations(); // [2] --- struts-default.xml,struts-plugin.xml,struts.xml
          3. init_LegacyStrutsProperties(); // [3] --- 自定义struts.properties
          4. init_CustomConfigurationProviders(); // [5] ----- 自定义配置提供 init_FilterInitParameters() ; // [6] ----- web.xml
          5. init_AliasStandardObjects() ; // [7] ---- Bean加载
      3. 创建Action类的三种方式
        1. POJO类 --除了继承Object类 ,不存在其他继承,实现的类 优点:无耦合 缺点:都要自己去实现.
        2. 实现Action类接口 --实现接口的execute方法,并且提供5个返回视图. 优点:耦合度低 缺点:都要自己去实现.

        3. 实现ActionSupport类 --在Action接口的基础上加强了 表单校验,错误信息设置,获取国际化信息 优点:耦合低 提供的功能多.
      4. struts.xml配置
        1.  <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd">
          <struts> <!--各种配置--> </struts>
      5. Action配置
        1. 1 <package> //声明一个包,管理Action.
          2 name //这个包的名称[唯一值]
          namespace//和Action的name 属性合并确定一个唯一的地址
          extends//要继承的其他包明
          abstrace//这个包是否可以被继承 true可以继承
           <action> //声明一个Action.
          name //和包的namespace 合并 确定一个唯一地址
          class //这个action要去调用类的类全名 查看Action创建的三种方式 默认第三种
          method //这个action要去执行这个类的方法 默认[execute] <result>用于确定返回结果返回视图
          name //和action[method]返回结果对应,返回一个视图.默认[success]

          1. 演示:
          2.   <package name="default" namespace="/" extends="struts-default">
            <action name="hello" class="cn.itcast.action.DefaultAction">
            <result>/hello.jsp</result>
            </action>
            </package> 此时输入: http://localhost/struts2_day01_2/a/b/c/hello 也访问到了action。 * 原因:struts2中的action被访问时,它会首先查找
            * .namespace="/a/b/c" action的name=hello 没有.
            * .namespace="/a/b action的name=hello 没有
            * .namespace="/a" action的name=hello 没有
            * .namespace="/" action的name=hello 查找到了.
            * 如果最后也查找不到,会报404错误.
          3. 默认Action的配置和作用
          4.  作用 处理其他Action处理不了的路径.
            <default-action-ref name="action的名称" />
            class 指定当前包默认执行的类.

struts2简单入门的更多相关文章

  1. 【java开发系列】—— struts2简单入门示例

    前言 最近正好有时间总结一下,过去的知识历程,虽说东西都是入门级的,高手肯定是不屑一顾了,但是对于初次涉猎的小白们,还是可以提供点参考的. struts2其实就是为我们封装了servlet,简化了js ...

  2. struts2简单入门-配置文件-struts.xml

    struts.xml 作用:配置struts中的action,result,package,全局action,result,等等. 基本文件格式: <?xml version="1.0 ...

  3. struts2简单入门-执行流程

    简单的执行流程图

  4. struts2简单入门-数据校验

    数据校验流程 校验数据的方式 重写execute方法在内部写校验代码 public class LoginAdminAction extends ActionSupport { private Use ...

  5. struts2简单入门-OGNL表达式

    什么是OGNL表达式 Object-Graph Navigation Language的缩写. 可以遍历整个对象结构图,实现对象类型转换等功能的表达式. OGNL实际上是个Map集合,有一个上下文根对 ...

  6. struts2简单入门-关于Result标签Type属性的说明

    Result标签 作用 当action执行完毕,后要返回什么样的视图. Type属性 决定返回的是什么视图. struts-default.xml的Type属性的定义 <result-types ...

  7. struts2简单入门-参数传递的三种方式

    三种方式的简单说明 属性传递 把参数定义为属性提供get/set方法. 使用情况 参数少,不需要共享. 演示代码 public class LoginAction extends ActionSupp ...

  8. struts2简单入门-Action的三种配置方式

    普通的配置方式 优点:可读性高 缺点:重复的配置太多. 使用情况 一个actian只有一个方法,只需要处理一种请求. 代码演示 <action name="voteResult&quo ...

  9. 【java开发系列】—— spring简单入门示例

    1 JDK安装 2 Struts2简单入门示例 前言 作为入门级的记录帖,没有过多的技术含量,简单的搭建配置框架而已.这次讲到spring,这个应该是SSH中的重量级框架,它主要包含两个内容:控制反转 ...

随机推荐

  1. A1087. All Roads Lead to Rome

    Indeed there are many different tourist routes from our city to Rome. You are supposed to find your ...

  2. RAP Mock.js语法规范

    Mock.js 的语法规范包括两部分: 数据模板定义规范(Data Template Definition,DTD) 数据占位符定义规范(Data Placeholder Definition,DPD ...

  3. 斯坦福大学公开课机器学习: neural networks learning - autonomous driving example(通过神经网络实现自动驾驶实例)

    使用神经网络来实现自动驾驶,也就是说使汽车通过学习来自己驾驶. 下图是通过神经网络学习实现自动驾驶的图例讲解: 左下角是汽车所看到的前方的路况图像.左上图,可以看到一条水平的菜单栏(数字4所指示方向) ...

  4. Doing Homework HDU - 1074 (状压dp)

    Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every ...

  5. (链表 递归) leetcode 24. Swap Nodes in Pairs

    Given a linked list, swap every two adjacent nodes and return its head. You may not modify the value ...

  6. node(基础三)_模块系统基础

      一.前言                                                                                         这篇文章主 ...

  7. Linux最常用的基础命令

    Linux最常用的基础命令个人总结 计算机基础知识: 32bit和64bit系统的区别.系统运行机制 32bit=内存的最大寻址空间是2**32,也就是说最大只能使用4GB的内存64bit=内存的最大 ...

  8. nlp知识

    1.词集模型 将每个词的出现与否作为一个特征,不考虑词频.也就是一个词在文本在文本中出现1次和多次特征处理是一样的. 2.词袋模型 与词集相比,会考虑词频 sklearn中 CountVectoriz ...

  9. 全角的空格(A1A1)惹的祸!

    #先上干货 “A1A1”是指全角的空格(GBK码): #验证 由上图可以看出半角的空格的HEX为"20": 由上图可以看出,在ANSI格式编码的文件中输入的全角的空格,转换为HEX ...

  10. Hadoop记录-hadoop和hbase监控有那些比较好的工具

    New Relic hadoop  jmx granfa falcon Ganglia,Nagios和Chukwa 自带监控软件 hadoop yarn 开启jmx监控 打开{hadoop_home} ...