Struts configuration file (any filename.xml):-
- Actionservlet looks to take WEB-INF / struts-config.xml file name & location as the default name & location of struts-configuration file. If any other name or location if chosen it must be specified in web xml file during ActionServlet configuration.
- Struts configuration file must be prepared based on the DTD rules supplied by apache foundation. (Craters of struts)
- ActionServlet uses struts config.file entries as guidelines while generating the integration logic dynamically.
- Struts config.file contains form beans, action class, and action forwards configuration to make them recognized by ActionServlet.
- The java bean class that extends form predefined Action form class is called as “Form Bean” class.
- Every Form bean must be configured in struts config.file having logical name.
RegisterForm.java:-
Public class registerform extends org.apache.struts.action.ActionForm
{
//form bean properties declaration
Private String username;
Private string password;
Public void set xxx (-) 2nos
{
——-
——–
}
Public string get xxx (-) 2nos
{
———–
——-
]
- The number variables of form bean class are called as “Formbean properties”.
- The names & count of these formbean properties must match with the names & count of form components in formpage.
In struts configuration file:-
<form-beans>
<form-bean name = “ref” type = “registerform”>
</form-bean>
- The java class that extends from predefined action class is called as struts Action class. This class contains execute method returning Action forward object pointing to result page.
- Every struts action class must be configured in struts-config. File having action path & by specifying the related form bean, result pages (action forwards)
- The process of linking Form bean & action forwards (result pages) with action class is technically called as Action mapping operation.
- A Form bean is identified through its logical name. An action class is identified its action path.
- An action forward configuration that points to result page is identified its logical name.
RegisterAction.java:-
Public class Register Action extends org.apache.struts.action.Action
{
Public ActionForward execute (-,-,-,-,)
{
—————
—————–
Returns ActionForward obj (with logical name)
}
}
In struts-config file (xml file):-
<struts-config>
<form-beans>
<form-bean name = “ref” type =”RegisterForm”/>
</form-beans>
<action-mappings>
<action path = “/reg” type = “RegisterAction” na, e =”ref”>
<forward name = “ok” path = “/result.jsp”/>
<location>
<location-mapping>
</struts-config>
1) “ref” is logical name of frombean configuration
2) Register form is javabean i.e acting as formbean class.
3) “/ref” is the action path of action class.
4) Register action is java class i.e acting as struts Action class.
5) Form Bean logic name “ref” here it is used to link form bean with action class.
6) “ok” Action Forward configuration logic name
7) “result.jsp” is the result page of current struts Action class (Register Form)