Tutorial on Struts Configuration
Struts, the open-source framework from Apache, offers integration with Java Beans and Java Server pages to provide a model-view-controller design pattern. Struts provides libraries of tags to work with the data model and action classes to work with the controller logic. The main purpose of Struts is to serve as the controller aspect of this design, while Java Beans connects with the database and JSP works to control the display of Web pages for the view.
Instructions
-
-
1
Open the "struts-config.xml" file in a text edition or through your IDE (integrated development environment) program. The file contains five main parts needed for Struts to work: form beans, global forwards, action mapping, controller configurations and application resources.
-
2
Add the name of each ActionForm within the "<form-beans>" tags. Each form bean should have the syntax <form-bean name="form_name"
type="myclass.example.form_name"/> with "form_name" describing the name of the form and "myclass.example" describing the path to the Java package.
-
-
3
Add the pages that Struts should redirect to between the "<global-forwards> tags. File that end in ".do" serve as the connection between the Struts controller and the application. Files that end in ".jsp" are the Java Server page files that process the form. Global forwards should have the syntax "<forward name="action1" path="/action1.jsp"/>. "
-
4
Create action mappings to connect form beans to global forwards using the "<action-mappings>" section. Action mappings should have the syntax "<action path="/pathtoaction" type="myclass.example.form_name"
name="form_name" scope="request" validate="true" input="/form_logic.jsp"> <forward name="success" path="/confirmation_page.jsp" redirect="true" /> <forward name="failure" path="/try_again.jsp" /> </action>."
This example connects two forwards to the form, one for a successful completion and one for a failed entry.
-
5
Create the controller with the extended controller tag of "<controller
processorClass="org.apache.struts.action.RequestProcessor" />."
-
6
Enter the parameters in the message resources section. Add "<message-resources parameter="myclass.ApplicationResources"/> if it is not already there. "Myclass" represents the Java package name.
-
1