Login Example with Spring and Struts 2 Integration
In the previous example, we have simply integrated the spring application with struts 2. Now let's develop a login application with struts 2 and spring frameworks.
It is the simple example of login application without database and session management. If you need to apply the database interactivity and session management with this example, visit this link Login and Logout example in struts 2.
Example of Login application Spring and Struts2 Integration
You need to create following files for simple login application using spring and struts 2 application:
This page gets the name and password 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 com.javatpoint.Login class. It will be considered as the action class here.
It defines four properties name, password, successmessage and errormessage; with execute method where success is returned if password is javatpoint.
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.