Struts Different Action and Actionform combinations Select Blog from 9CBS Sean_Gao to see a good text on TSS.com, and the pros and cons of various ACTION and ACTIONFORM combinations in Struts. I will die first, organize it, for your reference. Original title: Struts action mappings: Divide Et Impera, Author: Michael Juravlev. URL: http://www.theserverside.com/articles/article.tss? L = strutsactionmapping Description: Read this article requires a certain Struts foundation. Note: The action in the text does not necessarily represent the specific Struts Action class, and sometimes refers to an integral action mapping. [1] Complete action name = "someform" infut = "somejsp.jsp" action> First, Struts's ActionServlet receives a request, then locate the corresponding mapping according to the configuration of Struts-Config.xml; next If the Form range is request or can't find this form in the defined range, create a new Form instance; get the form () method, then call its reset () method, then put the parameters in the form into the form, if the validate property Not false, call the validate () method; if validate () returns non-empty ActionerRors, it will be transferred to the URI specified by the input property, if returned to an empty ActionerRors, then execute the action () method, based on the ActionForward Determine the target URI. The effect of this is: execute () is only executed after Validate () successfully; the input property is specified by a URI.
[2] Only Form's action First, Struts will search Someform in the defined Scope, if you find it, if you can't find a new instance; get the form () method, then call its RESET () method, then place the parameters in the form into the form, if the validate property Not false, call the validate () method; if validate () returns non-empty ActionerRors, it will be transferred to the URI specified by the input property, and if you return to the empty ActionerRorse, go to the target URI specified by the Parameter property. The effect of this is: No Action class can store our business logic, so all logic that needs to be written can only write to the form () or validate () method. The role of validate () is to verify and access the business layer. Because the action map here does not include Forward (meaningless), it cannot be redirected and can only be used with the default Forward. This Action only forms can be used to process data acquisition and forward to another JSP. [3] Only an action action input = "somejsp.jsp" action> First, after the ActionServlet receives the request, obtain the Action class instance, call the execute () method; then find Forward, forward to specify in the configuration according to the ActionForward URI or Action. The effect of this is that there is no form instance being incorred to be incocute () method, so execute () must obtain parameters from the request. Action can be redirected by Forward or redirect. This Action cannot handle the request submitted by HTML Form, which can only handle the link-type request. [4] Only JSP action First, the ActionServlet receives the request to call ForwardAction's Execute ( Method, execute () is forward to that URI based on the configured parameter property value.
The effect is that there is no form being instantiated, and the relatively realistic situation may be defined in the Request higher level; or this action is used as a system parameter after the application is compiled, only needs to change this The configuration file does not need to recompile the system. [5] Two Actions corresponds to a form name = "Someform" inform = "somejsp.jsp" action> name =" someform "infut =" someotherjsp.jsp " action> For each separate action, there is no substantial difference between processing and complete ACTION. This combination mode can be used to deliver the command object (FORM). It should be noted that the FORM RESET () and validate () methods are also called in the latter action, so we must ensure that the information in the form is not overwritten. The way to process is roughly divided into two: a) Put a indicator in the request indicating that the previous action is intended to pass the action, so that after the latter action can preserve the value in the Form, this way can only be Use forward when using Forward. b) When using redirect instead of Forward, you can put the indicator in the session or higher level, and clear this indicator at the last ring of the command chain. [6] Two action corresponds to two form name = "someform" inform = "somejsp.jsp" action> " name = "someotherform" infut = "someotherjsp.jsp" action> This combination is not much different from the previous process, but we now provide FORM for two Actions, so the code looks clearer. So we can separate Handle the input and output of the web application.
It is worth noting that the latter action will also try to write those parameters into the Form, but we can do this: a) use another set of attribute names in the latter Form; b) only provide Getter without providing setter. The general processing is this: the previous Action receives input, verification, then writes data into the business layer or persistence layer, redirects to the latter action, the latter Action manually removes the data from the business layer / persistence layer, writes Form ( Pass by other ways) to the front desk JSP display. The advantage of this is that it is not necessary to retain the value in the form, so it can be used to use Redirect instead of Forward. This reduces the coupling between the two anctions while avoiding unnecessary repetitive submission. Author Blog:
http://blog.9cbs.net/sean_gao/