When Struts Framework Will Be Activated in The Struts Application

Question:– When Struts framework will be activated in the struts application?

Answer: – When servlet container instantiates ActionServlet class (crates object) the ActionServlet activates Struts framework by using the jar files that are kept in WEB-INF/folder of Struts application.

  • This process takes place either during server startup/during deployment of the web application when <I-O-S> is enables on ActionServlet. If ActionServlet is not enabled with <I-O-S> then the above process takes places when ActionServlet gets 1st request from the browser window.

Note: – When ActionServlet obj. is destroyed the Struts framework will be destroyed.

  • Where traditional html tags based form page is launched on the browser window no form bean class object will be created.
  • When Struts supplied jsp tags based form page is launched on the browser window the related form bean class obj. will be created & the get xxx() will be called on that obj.  By ActionServlet to read default data from form bean class obj. & to place that data as initial values of form components in form page.
  • We can see form bean class object residing in two scopes.

1)      Request scope

2)      Session scope. (Default)

  • When form bean scope is “request” for every operation i.e performs on the form page one form bean class obj. will be created like when form page is launched or when form page is submitted.

Example:- In struts- configu.xml

        <action path = “/register” type = “app.register Action” name = “rf” scope = “request”>

  • If form bean scope is “session” irrespective of no. of operations you are performing on the form page on the form page one form bean class object will be created on one per browser window basis.

Example:- <action path =”/register” type = “app.RegisterAction” name = “rf” scope = “session”>

  • When you launch same form page for multiple times in a single browser window. If you want to see previous request data as the initial values of form components when form page is launched then take form scope as “request”.
  • We cannot place form bean object in application scope. But Struts action class object runs in application scope by default and it cannot be changed. Application scope means only one will be created for multiple request coming from multiple browser windows.

Leave a Reply

Your email address will not be published. Required fields are marked *