The attribute property for Actin Mpping is in the absence of!

zhaozj2021-02-12  158

In many cases, Attribute and Name in Action Mapping have been troubled me. Today I think it is determined to unclear this nail.

Turn some information. . . . .

Such two properties are set forth in "CONFIGURING JAKARTA STRUTS" in "Programming Jakarta Struts" in "Configuring The Struts Application" in this book: (102) Atribute: The name of the request or session scope attribute under which the form bean for this action can be accessed.A value is only allowed here if there is a form bean specified in the name attribute. This attribute is optional and has no DEFAULT VALUE.

Name: THE Name of The Form Bean, IF ANY, THAS Associated with this action. this value must be the name attributefrom one of the form-bean elements defined Earlier. This attribute is optional and has no default value. It is really not good to distinguish between these two. However, after carefully read the source code of Struts, it is clear. . .

The following is mainly explained to Attribute, and there should be no one will not understand the Name property (huh, ...)

Interpretation: When Struts instantiates Actionform, there are two cases: if there is already, then retrieved from memory; if you first instantiate, create, and put in memory. This has a problem. Struts is based on what to retrieve and create an actionform, the answer is the value of Attribute. Let us enter the Struts source code:

/ *** * create or retrieve formbean method in which: org.apache.struts.util.RequestUtils in * / public static Actionform createActionform (HttpServletRequest request, ActionMapping mapping, ModuleConfig moduleConfig, ActionServlet servlet) {. . . . . . . // is the a form bean associated with this mapping? // Get the value of Attribute in Action Mapping string attribute = mapping.getattribute () ;. . . . . . . . Actionform instance = null; httpsession session = null; // yes !! is here, put the actionform after the creation is placed in the request or session, see the name of the place, is mapping.getattribute (); if ( "request" .equals (mapping.getScope ())) {instance = (Actionform) request.getAttribute (attribute);} else {session = request.getSession (); instance = (Actionform) session.getAttribute (attribute);} . . . . . . } There is another problem with a problem: if I don't specify Attribute in the action maping, how is Struts solved? The answer is very simple. If you look at the results, the value of the Name used in Struts, why, see struts Source code: / ** * The request-scope or session-scope attribute name under which company t bean is accessed If IT IS DIFFERENT from the form> name . * This code is in: org.apache.struts.config.Anfig * / protected string attribute = null;

Public String getAttribute () {// yes !!!! is here, see it, if you don't set Attribute, Struts will take Name's value. Ha ha. . . IF (this.attribute == null) {return (this.name);} else {return (this.attribute);}}

public void setAttribute (String attribute) {if (configured) {throw new IllegalStateException ( "Configuration is frozen");} this.attribute = attribute;} If someone asked if I was not in the action mapping name in it? . . . . Dizzy ~~~~ `` Everyone is learning!

This post was originally posted in the struts area of ​​CJW (http://www.chinajavaworld.net)

转载请注明原文地址:https://www.9cbs.com/read-6114.html

New Post(0)