Updated July 5, 2023
Introduction to Struts Framework
The web application framework to develop Java EE web applications is called Struts. Struts were developed by Craig Mcclanahan in May 2000 and were given to Apache foundation. It was also called Jakarta Struts. It is written in Java and it uses cross-platform such as Java Virtual Machine. Struts are open source and use Java API. The license is Apache license 2 versions. Java Servlet API is extended to use Model View Controller Architecture (MVC) and it works basically among these three forms. Apache Struts framework is replaced by Struts 2 in February 2007.
Framework of Struts
- Controllerservlet and ActionServlet are provided in the framework. These are defined in the libraries and also in the Integrated Development Environment. Hence they get registered in the XML files used in the framework. Java servlet application interface is used that has a Model View Controller Architecture (MVC).
- The model is separated from the view and controller. Model is the application logic to interact with the database and View is the HTML page viewed by the client.
- A controller servlet called Action Servlet is used when the framework is started. The templates to be viewed by the user are created by Action servlet. The controller passes the information between the Model and View of the client.
- The templates are written using JSP for the HTML content.
- The programmer creates the configuration file called struts-config.xml. This config file keeps the model, view, and controller together.
- This servlet maps requests to Struts Action objects using struts-config.xml.
- If any information has to be changed, updating in the XML file should be more than enough.
- Action form objects are created to temporarily store data and the requests are executed.
- The model returns a string (Action forward) to instruct the controller to send an output page to the client.
- Once the requests are processed, Action object processes new data and results are forwarded to the appropriate view.
- The model and client pass information using a form called JavaBeans.
- A custom tag library is used to read and write the content of the beans and hence Java code is not needed.
- Web forms are internationalized using Struts and templates are created for the presentation layer. The template mechanism is called Tiles.
- The struts-config file is used to process application Action classes and result pages. These files save all the results and if any change is needed, those can be made in these files.
- Java annotations are used to provide metadata information and that helps the developers to create the application based on the information provided.
- The applications can be integrated with any other framework or application.
- Whenever the requests are made, actions are created and the servlet response to the model calls.
- UI tags, control tags, and action tags are provided so that struts are easy to use.
- XHTML, css_html and simple are the themes of struts where XHTML is the default theme.
- Threads are created to handle requests in servlet technology and hence separate memory areas are not created.
- The presentation layer is mixed up with business logic and the servlet needs to be recompiled if there is any code change.
- It is pretty easy and fast to develop web applications.
- Maintenance was a concern as the pages were decentralized and logic has to be determined to write the subsequent pages.
Advantages of Struts
- Since Struts follow MVC framework, Java, JSP and Action classes are highly maintained and easy to understand for developers.
- The development time is less and this creates an advantage for the application developers.
- It is easy to maintain the applications due to the MVC framework.
- The representation is in xml or property files and hence all the information about the application can be collected from the xml.config files. All information including Action class, Form Bean and JSP page information is in the config file which is very helpful for the developers.
- getParameter () information is stored in Form Bean. All the input data is processed here. The time to process the data is very less due to Form Bean.
- JSP tags are provided that easily provide the properties of JavaBeans components. The tags are customized, concise and powerful when compared to other tags.
- HTML tags are also created from JSP tags to set the page for the user interface. The form field objects are from Java files. The forms can be redisplayed with all the values remaining the same or a few changes made.
- In order to check whether the form values are in the required format, Struts has built-in capabilities. This helps to get the values sooner for developers.
- The configuration is centralized and it proves as an advantage for forms and Action classes.
- Due to xml and property files, any changes can be made to these files without changing the original Java code. Hence the developers need not know the entire layout. They have to edit only the single file. This helps to save the time of editing the file.
- The validator in Struts is really good to validate the forms or fields whatever the developer entered in the network. This validation is either performed in the server or in both server and client.
- The infrastructure is taken care of well in Struts. HTTP requests are mapped into the process and developers need not worry the same. They can focus on the code and developing the domain.
- Documentation is well maintained and is of very useful to anyone who develops the framework.
Struts are a large framework and hence used to create enterprise-wide applications. The design, action form, and annotations are simple and easy to understand. Struts are mainly considered as a legacy and if it is needed very much by the client, we should follow the same. This framework is popular due to ease of use and knowledge of Java by developers.
This is a guide to the Struts Framework. Here we discuss the introduction, Framework, and advantages of Struts in detail. You may also look at the following articles to learn more –