Struts framework helps for developing the web based applications. Struts java framework is one of the most popular framework for web based applications.Java servlet, JavaBeans, ResourceBundles and XML etc are the Jakarta commons packages used for accomplishing this purpose. This is an open source implementation of MVC pattern for the development of web based application. The features of this type of framework are,
- More robust or reliable architecture
- Helps for development of application of any size
- Easy to design
- Reliable web application with java.
When a request happens the parameters interceptor passes the requested data to the ValueStack. After transferring the request the OGNL do the job of changing the string based form data to their related java types. OGNL complete or do this by using the set of available built-in type converters. After that when the results are generated the OGNL converts the java types of the property on the ValueStack to the string-based HTML output. ActionContext is act as thread local which helps the values stored in the ActionContext are unique per thread, this makes the Struts 2 actions thread safe.
Strut implements the Model-View-Controller (MVC) design pattern.
- Model: – The model includes the core of the application’s functionality. It wraps the state of the application. Sometimes the only functionality it contains is state. Model category not bothered about the view or controller category.
- View: – The view gives the presentation of the model. It is the look of the application. The view can access the model getters, but it has no knowledge of the setters. In addition, it knows nothing about the controller. The view should be notified when changes to the model occur.
- Controller: – The controller reacts to the user input. It creates and sets the model.
The MVC implemented by the action, result and FilterDispatcher respectively. In MVC the controller’s job is to map the user request to appropriate action and this job is done by FilterDispatcher. The model includes the data and the business logic and the model is implemented by the action component. The presentation component of the MVC pattern is view and view is implemented using JSP, Velocity Template, Freemaker or some other presentation-layer technology.
1) Action handler:- The action handler interacts with other layers
2) Result Handler: – The result handler actually dispatches the request to view.
3) Custom Tags:- The custom Tags are used render the dynamic content
4) Interceptors: – An interceptor permits to adding some custom logic such as authentication, file upload to an action. Interceptors code is run before and after an Action is invoked
5) Value Stack: – The ValueStack permits the expression language to find property values across multiple objects. Thus Struts2 tags can access data from the action very easily.
6) Expression Language:- Struts 2 expression language is used for getting and setting properties of Java objects
7) Controller: – The controller receives all incoming requests. Its primary function is the mapping of a request URI to an action class selecting the proper application module.
8) Struts-config.xml file:- This file includes all of the routing and configuration information for the Struts application.
9) Action classes: – It’s the developer’s responsibility to create these classes. They act as bridges between user-invoked URIs and business services. Actions process a request and return an ActionForward object that identifies the next component to invoke. They’re part of the Controller layer, not the Model layer.
11) ActionForms: – These greatly simplify user form validation by capturing user data from the HTTP request. They act as a “firewall” between forms (Web pages) and the application (actions). These components allow the validation of user input before proceeding to an Action. If the input is invalid, a page with an error can be displayed.
12) Model componenets: – The Struts Framework has no built-in support for the Model layer. A strut supports any model components. Some model components are,
5) any other
Features of strut frameworks
1) Open source
2) Implements the JSP Model 2 Architecture
3) Stores application routing information and request mapping in a single core file, struts-config.xml
4) The Struts Framework, itself, only fills in the View and Controller layers. The Model layer is left to the developer
5) OGNL and ValueStack: – OGNL stands for Object-Graph Navigation Language and it is a powerful expression language that is used to reference and manipulate data on the ValueStack. OGNL provides a mechanism of data transfer and type conversion. OGNL expression language provides simplified syntax to reference java objects. OGNL is used to bind the java-side data properties to the string-based view layer. In Struts 2 the action resides on the ValueStack which is a part of the ActionContext. ActionContext is a global storage area that holds all the data associated with the processing of a request.