If form bean is used to store the variables of the JSP form connected via action="submitDetailForm"
for example then what are ActionForm
s for?
Whats confusing about the app that I am working on is that it has forms that are actual beans but there's a bean folder that parses the request result.
Forms are mapped to the action. It doesn't matter which folder they belong. Sometimes classes for the form beans are in the same folder as action beans, sometimes the form beans are in the separate folder. Which folder is used you can find in the struts-config.xml
.
Everything becomes clear if you read Struts struts-config.xml action-mapping explained:
The
type
attribute of the<form-bean>
is used to enter FQCN of the bean class that would probably extend theActionForm
. It's needed by Struts to be able to instantiate a bean when required.
You can also read this article for quick overview of the framework Struts:
The
struts-config.xml
file can have several sections. The first section we will look at is the<action-mappings>
section.<action>
tells Struts which class to invoke from theActionServlet
. Only thepath
andtype
are required entries. Thetype
tells Struts whichAction
class to invoke when a URL with the model of thepath
is found.In order for a class to be entered in the
<action-mappings>
section and to be invoked byActionServlet
, it must extend the classorg.apache.struts.action.Action
(see Listing 3). TheActionServlet
will execute theperform()
method of theAction
object. The perform method looks like this:public ActionForward perform(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, javax.servlet.ServletException
The
ActionMapping
andActionForm
objects will contain information found in thestruts-config.xml
<action-mappings>
and<form-beans>
sections. TheHttpServletRequest
andHttpServletResponse
objects are from the servlet.