Spring and Struts 2 Integration
Spring framework provides an easy way to manage the dependency. It can be easily integrated with struts 2 framework.
The ContextLoaderListener class is used to communicate spring application with struts 2. It must be specified in the web.xml file.
You need to follow following steps:
Example of Spring and Struts 2 Integration
You need to create following files for simple spring and struts 2 application:
This page gets the name from the user.
It defines controller class for struts 2 and ContextLoaderListener listener class to make connection between struts2 and spring application.
It defines the package with action and result. Here, the action class name is login which will be searched in the applicationContext.xml file.
It defines a bean with id login. This beans corresponds to the mypack.Login class. It will be considered as the action class here.
It should be located inside the WEB-INF directory.
It defines two property userName and message with execute method where success is returned.
It prints values of userName and message properties.
It is the error page. But it is not required in this example because we are not defining any logic in the execute method of action class.