zoukankan      html  css  js  c++  java
  • Struts2初始(一)

    1、过滤器:org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
    位置:在struts2的核心包struts2-core.jar包中
    ----------------------------------------
    2、如何编写struts2的配置文件?
    struts.xml关联了控制器(Action)与视图(view)之间的联系,
    通过配置struts.xml进行视图与Action之间的一一对应关系。
    1)、导入struts的doctype--
    目的是为了导入struts的核心文件,
    告诉编译器怎么去读文件

    2)、<struts></struts>--
    相当于与html的<html></html>,
    标志着struts的开始

    3)<package></package>
    声明使用的struts框架的资源
    extends属性,声明请求/继承的struts中的包的资源是哪个
    struts-default值是指包资源来自于struts的默认包

    name:包名称

    namespace:包的命名空间是哪个

    4)<action></action>
    其作用是使我们的Action与显示页面进行一一的对应。
    name属性:用户定义的action标签的名称,访问该资源
    的url也是使用action的名称作为访问路径

    class:关联其所对应的Action类,填写该Action的路径

    <result></result>
    通过result标签关联jsp视图
    name:当执行完Action execute方法后的结果,
    对应的结果就显示对应的jsp页面,
    通过配置多个result标签是可以实现Action和
    视图形成一对多的关系


    ----------------------------------------
    使用struts的必要配置及作用:
    1)、Create a class to store the welcome message (the model)
    创建一个类存储欢迎信息--这个类属于业务层

    2)、Create a server page to present the message (the view)
    创建一个页面去显示这个信息--这个页面属于视图层

    3)、Create an Action class to control the interaction between the user, the model, and the view (the controller)
    创建一个实现Action接口的类去控制用户、业务、视图之间的交互---这个类属于控制层/器

    4)、Create a mapping (struts.xml) to couple the Action class and view
    创建一个映射文件(struts.xml)去关联Action与视图之间进行沟通

    通过这四个组件实现业务、视图、控制器之间的分离,降低
    这些层之间的耦合度。

    -----------------------------------------
    Action的其他实现方法
    Action实现由3种方式
    1、使用普通的java类,编写 execute 方法
    2、实现Action接口,实现execute方法。
    3、继承actionsupport类实现
    --------------------------------------
    static String ERROR
    The action execution was a failure.
    控制器执行失败,返回error
    static String INPUT
    The action execution require more input in order to succeed.
    控制器执行需要用户进行输入之后才会成功
    static String LOGIN
    The action could not execute, since the user most was not logged in.
    控制器没有执行时,则不能登录成功
    static String NONE
    The action execution was successful but do not show a view.
    控制器执行成功,但不显示页面
    static String SUCCESS
    The action execution was successful.
    控制器执行成功,并显示页面。

    String execute()
    Where the logic of the action is executed.
    重写此方法,当控制器执行时,会执行当前方法的业务逻辑。
    并会返回一个结果,告诉配置文件当前执行状态是哪个

  • 相关阅读:
    开篇有益-解析微软微服务架构eShopOnContainers(一)
    复杂而艰辛的重构之路--起步
    Visual Studio 我的插件
    【翻译】使用Visual Studio创建Asp.Net Core MVC (一)
    【翻译】使用Visual Studio在Azure上部署Asp.Net Core Web应用
    【翻译】在Visual Studio中使用Asp.Net Core MVC创建第一个Web Api应用(二)
    【翻译】在Visual Studio中使用Asp.Net Core MVC创建你的第一个Web API应用(一)
    【翻译】在Mac上使用VSCode创建你的第一个Asp.Net Core应用
    【翻译】Asp.net Core介绍
    新的一年订个小目标,比如每周更新1-2篇博文
  • 原文地址:https://www.cnblogs.com/sunzan/p/6068962.html
Copyright © 2011-2022 走看看