Basic flow of Struts

前端 未结 3 1209
情话喂你
情话喂你 2021-01-30 11:45

Well I want to study Struts so I am going to begin with Struts 1, I would like to know the general flow. What files are required?

Whats the function of struts-config.xml

3条回答
  •  耶瑟儿~
    2021-01-30 12:22

    Model


    Struts doesn't support Model directly. However, the Struts actions and configuration file provide you ability to implement it by your own.

    View


    1) Form bean that extends org.apache.struts.action.ActionForm, that is used in two ways at run time:

    • When a JSP page prepares the related HTML form for display, the JSP
      page accesses the bean, which holds values to be placed into the
      form. Those values are provided from business logic or from previous user input.
    • When user input is returned from a web browser, the bean validates and holds that input either for use by business logic or (if validation failed) for subsequent redisplay.

    2) Struts tag libraries such as bean, logic, html & tiles plugin

    Controller


    1. The Struts action servlet handles runtime events in accordance with a set of rules that are provided at deployment time. Those rules are contained in a Struts configuration file and specify how the servlet responds to every outcome received from the business logic. Changes to the flow of control require changes only to the configuration file.
    2. Struts action extends org.apache.struts.action.Action. At run time, the action servlet is said to "execute actions," which means that the servlet invokes the execute method of each of the instantiated action classes. The object returned from the execute method directs the action servlet as to what action or JSP file to access next. To facilitate reuse, invoke business logic from the action class rather than including business logic in that class.

    See the Struts 1.3 example

    For your comparison & reference, here's Struts 2.3 demo

提交回复
热议问题