|developer||Apache Software Foundation|
|Publishing year||October 10, 2006 to April 11, 2014|
|Current version||2.5.22 GA travelcard
(November 29, 2019)
|operating system||platform independent|
Struts is an open source - Framework for the presentation and control layer of Java - Web applications . Struts significantly speeds up web application development by processing HTTP requests in a standardized process. It uses standardized techniques such as JavaServlets , JavaBeans , Resource Bundles and XML as well as various Apache Commons packages.
For the developer, this means that many application-relevant functions are already implemented and ready for use. Struts is already used in a great many web applications and is widely regarded as a solid framework . Struts was developed by Craig McClanahan in 2000. Since then, a growing community of developers has been working to improve the framework. From version 2, the Struts framework is merged with the WebWork framework. The Struts approach was also used for the development of Struts4PHP.
As one of the most famous Jakarta projects , Struts advanced to an “Apache Toplevel Project” in 2004 .
The Struts framework is the design pattern " Model View Controller " basis. The components provided by Struts come from the areas of presentation (view) and program control (controller). Functions from the model area must be implemented elsewhere in an application. The framework currently contains around 300 Java classes, which are divided into eight core packages.
Model 1 architecture with JavaServlets / JSP
After the technology from Java - Servlets was introduced, we quickly realized that the creation of HTML may be pages with servlets time consuming and the further development of views very tedious. In addition, all three components of the Model-View-Controller concept were implemented in one servlet. Thereupon JSP was introduced, which made the work of the web designer especially easier and became established in a short time. This resulted in the Model 1 architecture , which describes that data management, business logic and view are to be located in a JSP, which, however, leads to new problems with complex application logic: The JSP becomes unmanageable in a very short time and can only be maintained by developers. who have both HTML and Java skills. The use of tag libraries (such as JSTL ) alleviates this problem somewhat, because Java code is no longer required. The basic conceptual problem of mixing presentation with technical functionality remains, however.
Model 2 architecture with Struts
The problems listed have contributed to the need to develop a new concept that separates the individual components more clearly and integrates Java servlets and JSP equally. The Model 2 architecture for web applications was created , which is used in the Struts framework. This uses a front controller , after which each call is first processed centrally and then forwarded to the corresponding controller.
- jQuery plugin
- Dojo plugin (deprecated)
- AJAX Client Side Validation
- Support for templates
- Different types of results
- Easy to expand with plugins
The aim is to separate presentation, data management and application logic . This increases the overview and the maintainability. The core elements in Struts to implement are:
- for program control, interface between the view and the application logic
- for presentation
The components are linked together in the Struts central configuration file .
<struts-config> <!-- FormBean Definitionen --> <form-beans type="org.apache.struts.action.ActionFormBean"> <form-bean name="RegisterForm" type="bar.foo.web.RegisterForm" /> </form-beans> <!-- Action Definitionen --> <action-mappings type="org.apache.struts.action.ActionMapping"> <action path="register" name="RegisterForm" type="bar.foo.web.RegisterAction" input="/web/register.jsp" scope="request" validate="true"> <forward name="success" path="/home.do" /> <forward name="failure" path="/error.do" /> </action> </action-mappings> </struts-config>
<struts> <constant name="struts.enable.DynamicMethodInvocation" value="false" /> <package name="myApplication" extends="struts-default"> <action name="index"> <result>/jsp/index.jsp</result> </action> </package> </struts>
<html:text name="RegisterForm" property="emailAddress" size="20"/>
Here the attribute “
emailAddress” of the action (Struts2) or form bean (Struts1) is filled with the content of the text field via the setter method after the form has been sent. An
<input type="text" size="20" name="emailAddress" value="..."/>HTML element is also generated in the JSP.
Struts also has a template extension called Tiles . They enable the developer to build his website on a component basis (header, footer, content, and so on). Tiles can include JSPs as well as other tiles.
The Form Bean (Struts1)
The form bean is a normal Java bean that contains all the data required for the JSP and the action. It is the interface between these two components and is linked
struts-configto a form in the JSP. When the form is submitted, the bean
ActionServletis fed with the appropriate input values via the setter methods (before the action is executed) .
FormBeanalso contains a validation method which, if activated in the configuration, checks the data of the form bean before it is sent to the action. It also contains a
resetmethod to reset the content so that it can be reused, which reduces the overhead for memory management (see: Slab allocator ).
Since this type of data management is often too rigid , the Struts developers created the option of declaring the beans in struts-config.xml , which eliminates the need for rigid and complex programming of the beans. For access, the is then cast
ActionForm to one of
DynaBeanthe Apache Commons BeanUtils project and the data is then queried using a key. When using dynamic beans, the Commons Validation Framework can also be used for validation .
The action is the component that communicates with the backend , fetches data from it and also writes it back to it. It usually contains further checking and evaluation mechanisms.
The action is also responsible for navigating the website, as it has to return a after the work is done
ActionForward. Depending on which forward the action returns, the Struts framework decides
struts-configwhich page should be forwarded to.
- WebWork - the basis of Struts 2
- Web application
- JavaServer Faces
- JavaServer Pages Standard Tag Library
- Matthias Weßendorf: Struts - develop websites efficiently with Struts 1.2 & 1.3 and Ajax. 2nd Edition. W3L, Herdecke 2006, ISBN 3-937137-26-2
- Michael Albrecht, Manfred Wolff: Struts packed. MITP, Bonn 2004, ISBN 3-8266-1431-3
- Website of the Struts project (English)
- Struts 2 Plugin Registry
- Struts2 jQuery plugin
- Introduction to Struts2 (English)
- Criticism of Struts1 (English)