Struts 2 - Understanding the working between OGNL and params interceptor

后端 未结 3 1022
耶瑟儿~
耶瑟儿~ 2021-01-15 05:21

I am new to Struts 2. I am studying it from the book Struts2 In Action. I am having difficulty in understanding some concepts in OGNL which are as follows-

  1. <
3条回答
  •  既然无缘
    2021-01-15 05:42

    Let us say you write Login page and corresponding Login Action. On page you have a text box which has a name that says that it is a name field of User object. You also have a password field on page that says it maps to pwd field on the User object.

    Now Object graph here would mean that it has to tell the params interceptor that the name field is actually a name field of user object in the login action. The action context, valuestack and OGNL will together have the knowledge that: Well maybe there are other actions as well, like FileUploadAction. And these other actions may also have a user object reference. But for current action context, the name field from the login page actually maps to nothing else but the name field of Login Action's user object. It does not belong to the name field of user object of FileUploadAction. They have this knowledge and also behave as if the field itself (actually the entire object graph) sits on value stack and is directly accessible. (A little background on ThreadLocal will be better to understand this.)

    The interceptors are chained and it becomes a chain of responsibility on the way forward and back. An interceptor may perform some action is forward direction or the return direction or both. So let us say the the flow is like below:

     Page 1-->Interceptor_1--> Interceptor_2 --> Interceptor_3 -->Action_1
    

    Then the return flow would be like below:

    Action_1 --> Interceptor_3  --> Interceptor_2 --> Interceptor_1 --> The result Page
    

    So, to answer your question, params inteceptor will be called in the return flow as well.

提交回复
热议问题