Resources of Struts 1.x Application – Struts Tutorial

Resources of Struts 1.x Application:-

  1. JSP program -> (view layer)  -> contains presentation logic.
  2. Action servlet -> (controller) -> contains integration logic.
  3. Web XML -> DD file -> contains configurations.
  4. Form beans class -> (controller layer) -> contains form validation logic.
  5. Action class -> (controller / model layer) -> contains Business logic & persistence logic (for other logic)
  6. Struts configuration file -> (XML file) -> controller layer
  7. Action forwards -> points to result pages.

The controller servlet program in struts application is action servlet. It is a built in servlet supplied by struts application.

Note:- except action servlet the remaining all the resources in struts 1.x application must be developed manually.

The Struts JSP programs:-

  • The presentation logic of these JSP programs generates user interface and also formats the results generated by business logics. It is always recommended to develop the JSP programs of struts application as java codeless JSP programs. For these it is recommended to use the following tags.
  • JSP tags of JSP technology:- (except script let, expression, declaration tags)
  • JSTL tags
  • Struts supplied JSP tag library tags
  • Custom JSP tags

Note: – Developing JSP program as java codeless JSP program is called as view helper design pattern implementation.

The Struts Action servlet:-

  • A built in controller servlet of every struts application having the capability to generate integration logic dynamically & automatically based on the configuration done in struts configuration file.
  • Action servlet takes struts-configuration XML file of WEB-INF folder as default struts- configuration file.
  • This actionservlet is httpservlet.

The Struts Web xml:-

  • It is called deployment descriptor (D.D) file of any java web application (including struts application).
  • In this file actionservlet, JSP tag library & web come files be configured.
  • Even though A-servlet is built in servlet its configuration in web xml file is mandatory operation.
  • For process of passing the details of certain resource to underlying server s/w or framework s/w or container s/w is called as “Resource configuration” file.

The Struts Form bean class:-

  • It is a programmer supplied java bean class extending form org. apache.struts.action.ActionForm class.
  • Having capability to hold the form data of form page.
  • Actionservlet writes the form data of form page to form bean class and programmer uses this form data to perform the form validations.
  • The predefined Action form class is on abstract class containing no abstract methods.

Question: What is the need of form bean class in struts application:-

A/c to MVC2 architecture the controller servlet is responsible perform form validations. In struts ActionServlet is built in controller servlet. So programmer cannot write form validation logic by editing the source code of ActionServlet.

To overcome above problem ActionServlet writes the receiver form data of form page to the programmer supplied form bean class. So programmer can write his choice of form validation logic in form bean class by using form data.

Form bean class is helper resource to ActionServlet in controller layer.

The Struts Action class:-

  • It is a programmer supplied user –defined java class having ability to act as either model layer resource or controller layer resource.
  • If business logic is directly placed in Action class it comes under model layer resource.
  • If logic is placed in Action class to comm. With other model later resource like ejb component or spring with hibernate app. Then Action class comes under controller layer resource.
  • Every struts action class is a java class extending form org.apache.struts.action.Action class.

Question: what is the need of taking struts action class as controller layer resource:-

  • A/c to MVC2 architecture the controller servlet is responsible for comm. With model layer business component like EIB component spring application spring with hibernate or etc.
  • In struts application ActionServlet is built in controller servlet. So programmer cannot edit the source code of this ActionServlet to place the code of comm. With the above said model layer business component.
  • To overcome these problems ActionServlet uses the support of struts action class to comm. with above said business component. Because Action class is the programmer supplied java class & it can contain logic to comm. With above said business component.

The Struts Struts configuration file:-

  • Any <file name>.xml can be specified as Struts configuration file during ActionServlet configuration in web.xml file.
  • If no file is specified ActionServlet looks to take struts config.xml file of WEB-INF folder as default struts-configure file.
  • This file is heart of the struts app. to provide guidelines & instruction to ActionServlet to generate integration logic dynamically and to decide the flow of execution. This file contains the following configuration.

a)      Form Bean class configuration.

b)      Action classes configuration.

c)       Action forward configuration.

d)      Plug-in configuration.

e)      Properties file configuration etc.

  • Action servlet reads struts-configure file
  • Servlet container reads web.xml file
  • Servlet container is responsible to create & manage form bean, Action class object.

The Struts Action Forwards:-

  • Xml entries in struts configure File pointing to the result pages of Action classes.
  • Action servlet uses these “Action forwards” to decide the result page of Action class to format the result given by Action class. These are controller layers.

Question: Can I write both web.xml & Struts-configuration file related xml entries in a single in a single xml file?

Answer:  Not possible, because these two files (web.xml, Struts-configure file) will not be read by single s/w environment. Actually two predefined s/w environment / resources like servlet container, ActionServlet are reading these two xml files. So they must be in two different files.

Leave a Reply

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