What is struts?
- Apache Struts is an open-source framework that is used for developing Java web application. Originally developed by the programmer and author Craig R. McClanahan, this was later taken over by the Apache Software Foundation in 2002. Struts have provided an excellent framework for developing application easily by organizing JSP and Servlet based on HTML formats and Java code. Strut1 with all standard Java technologies and packages of Jakarta assists to create an extensible development environment. However, with the growing demand of web application, Strut 1 does not stand firm and needs to be changed with demand. This leads to the creation of Strut2, which is more developer friendly with features like Ajax, rapid development and extensibility.
- Struts is a framework based on set of Java technologies like Servlet, JSP, JSTL, XML etc which provides implementation of MVC architecture. The power of Struts lies in its model layer by which Struts can be integrated with other Java technologies like JDBC, EJB, Spring, Hibernate and many more.
- ActionServlet is the name of a class that plays role of controller in Struts.
- Whenever the user sends a request to server it passes via ActionServlet which then decides the
necessary model and sends this request to the respective model. - Two more files support the flow of application: web.xml and struts-config.xml files. Web.xml file is
deployment descriptor which keeps all the application related settings while struts-config.xml file maps
a request to Action classes and ActionForms(a simple POJO which contains properties related to
UI). - Model is handled by various Java technologies like EJB, JDBC, Hibernate, Spring etc. It mainly
concentrates on the business logic and semantics of the application. - View can be developed using JSP, Velocity Templates, JSTL, OGNL, XSLT and other HTML technologies.
View is responsible for getting the input from the user and rendering the result of that input sent back
to user.
- Whenever the user sends a request to server it passes via ActionServlet which then decides the
Comparison with Spring and Hibernate
- Struts is used to develop only frontend framework while
- Hibernate is used to develop backend systems.
- In contrast to above two, Spring is complete and modular framework i.e., it works on front end as well as backend development. So technically you can say Struts and Hibernate are subset of Spring framework.
- Struts uses Action class to write business logic while
- Spring uses Controller classes.
- Hibernate DAO classes contains the logic related to the persistence of object.
- Action class in Struts is an abstract class while
- Controller class in Spring is Interface so performance vice Controller class of Spring is better than Action class of Struts.
- The main reason is a java class can only extend one class, but at the same time it can implement any number of interfaces, hence it is better to use interface rather than using abstract class.
- ActionForward in struts is replaced by
- ModelAndView object in Spring
- Struts implements MVC architecture.
- Hibernate is ORM based framework.
- Spring framework is very modular and has multiple modules. Spring MVC module is based on MVC design pattern. It supports IOC, AOP, ORM etc.
- Main advantages of Spring framework is Transaction Management and Messaging support. In addition to this Spring is very powerful with support of IOC, AOP, MVC, ORM and much more. Also, Spring can be easily integrated with other frameworks like struts, hibernate etc.
- The advantages of Struts framework are elegant tag library support and easy integration with other front-end technologies.
- The main advantage of Hibernate framework is database independency because Hibernate uses HQL to develop database independent queries.
Example
- https://www.javatpoint.com/steps-to-create-struts-2-application-example
- Spring and Struts 2 integration: https://www.javatpoint.com/spring-and-struts2-integratio
