Components of struts architecture
· Struts s/w is created based on Mvc architecture. So, all struts based web application are Mvc architecture based web app due to this various resources of struts application acts as various model, view, controllers layer component
· Component of struts architecture or struts application development
o Jsp files/Html files:
§ It contains presentation logic belongs to view layer
§ It is always recommended to develop jsp as of struts app as ‘java code less’ jsp by using following tags;
· Standard jsp technology tag
· JSTL(Jsp Standard Tag Library)
· Struts supplied jsp tags
· 3rd party tags
· Custom jsp tags
Note: What Is a Custom Tag?
A custom tag is a user-defined JSP language element. When a JSP page containing a custom tag is translated into a servlet, the tag is converted to operations on an object called a tag handler. The Web container then invokes those operations when the JSP page's servlet is executed. Custom tags have a rich set of features. They can
-Be customized via attributes passed from the calling page.
-Access all the objects available to JSP pages.
-Modify the response generated by the calling page.
-Communicate with each other. You can create and initialize a JavaBeans component, create a variable that refers to that bean in one tag, and then use the bean in another tag.
-Be nested within one another, allowing for complex interactions within a JSP page.
o ActionServlet:
§ Built-in servlet acting as controller in struts based web app
§ This action servlet contain logic to generate integration logic of the controller layer dynamically in struts based web app
§ This action servlet is built in servlet extending from javax servlet.http.Httpservlet class
§ The fixed code of action servlet generates integration logic dynamically based on the resources available in other layers of struts app
o Web.xml:
§ Deployment description file (DD file)
§ This file contains ActionServlet configuration ,welcome file configuration, jsp tag libraries config and etc
§ Even though ActionServlet is built in and predefined servlet it has to configured with web.xml file then only the underlying servlet will recognizes a ActionServlet
o Form beam class/action form class:
§ It is .java class, and it will be in controller layer
§ this is programmer supplied java bean class to struts app as helper class to ActionServlet
§ ActionServlet creates object of this class and writes form data collected from page
§ So, that programmer can use this form data in form bean class to write form validation logic.
FAQ
What is the need of formbean class in struts app?
- Action servlet is the controller servlet in struts based web app as a controller it must contain form validation logic of programmer end. Since this action servlet is built in servlet, the programmer can’t write his own choice of form validation logic in action servlet
- To overcome this problem action servlet populates form based form data to programmer supplied form bean class object. So that programmer can used this form data in form bean class to write form validation logic
Note:
The java bean class that can store form data of the struts application is called form bean class the javac class that extends from org. apache.struts.action.Actionform class is called formbean class
o Action class:
§ It is .java
§ it will be in controller layer/model component
§ If action class directly contains business logic then it is called model component.
§ If action class contain logic to communicated with other model layer Component like ejb, spring, hibernate application then it is called helper resource to the controller servlet called ActionServlet
§ The java class that extends from org.apache.strut.action.Action class is called action class of struts application
FAQ
What is the need of action class in struts application?
-If a programmer wants to keeps business logic in struts application without taking the support of separate layer technologies, then the programmer keep business logic and related persistence logic in action class and makes that class as model layer component
-Controller servlet of Mvc app is responsible to communicate with model layer components
-In struts app action servlet is built in servlet. So that programmer can’t write his own choice logic that in action servlet to communicate model layer components like ejb, spring app etc
-To solve this problem action servlet ask the programmer to place a java class having logic to communicate with other model components and this action servlet and communicate with this java class for every request. This java class is nothing but action class of struts app. In this situation action class acts as helper to controller servlet (action servlet)
o Action forwards
§ These are xml statements, configuration result pages (like jsp) for ActionClasses
§ So that the result generated by Actionclass or the result received by Actionclass from other model component will be formatted by executing the presentation logic of result jsp ’s and this formatted result goes to browser as response
o Struts configuration file:
§ It is xml file and it will be in controller layer
§ This file contains formbean, ActionClasses action forward and other plug-in configuration
§ ActionServlet reads this files and use this file configuration as base for generating integrates logic dynamically
§ In this process ActionServlet uses a built in class called request processor internally
§ Any <files>name.xml can act as struts configuration ActionServlet takes WEB-INF\struts-config.xml file as default struts configuration file. Programmer can place his choice file name as struts configuration file in web.xml file during the configuration of ActionServlet