ActionServlet in-depth discussion --3

xiaoxiao2021-03-06  110

In INitMapping (), first link the mappings object to this servlet instance. In fact, this sentence is very simple, there will be an ActionServlet type attribute in ActionMappings, which defines the ActionServlet to which this ActionMappings object belongs. Struts is more flexible, where ActionFormBean, ActionForward, ActionMapping class You can customize Struts's working methods using your own subclasses. The above code reads the FORMBEAN, Forward, Mapping parameters from the configuration file (web.xml), which is the ActionFormBean, ActionForward, ActionMApping class name you customized.

// Initialize the Context-Relative Path To Our Configuration Resources

Value = GetServletConfig (). getInitParameter

"config");

IF (value! = null)

CONFIG = VALUE;

// acquire an input stream to our configuration resource

InputStream INPUT = GetServletContext (). GetResourceAsStream (config);

Digester Digester = NULL DIGESTER = NULL;

Digester = initdigester (detail);

Try {

Formbeans.setfast

FALSE);

Forwards.setfast

FALSE);

Mappings.setfast

FALSE);

Digester.parse (Input);

Mappings.setfast

True);

Forwards.setfast

True);

Formbeans.setfast

True);

}

Catch (SAXEXCEPTION E) {

Throw

New servletexception

(Internal.getMessage (INTERNAL.GETMESSAGE

"Configparse", Config, E);

}

Finally {

INPUT.CLOSE ();

}

Read the position of the Struts configuration file from Web.xml. Use org.apache.struts.digester.digester to parse the configuration file indicated by the config parameter, usually "/Web-inf/Struts-config.xml", resolve all Data-Source, Form-bean, action-maping, forward . As seen from the previous program, Digester only calls a parse () method, how does Digester use the Struts-Config.xml file and store the resolved result for FORM-BEAN to the attribute variable FORMBEANS, etc. ? You can notice that the initdigester () method first calls Digester.Parse (InputStream):

Digester digester =

New digester ();

Digester.push

THIS);

Digester.addObjectcreate

"struts-config / action-mappings / action",

MappingClass,

"classname");

Digester.AddSetProperties

"struts-config / action-mapings / action"); Digester.AddsetNext (

"struts-config / action-mappings / action",

"addmapping",

"org.apache.struts.action.actionmapping");

Digester.AddSetProperty

(

"struts-config / action-mapings / action / set-property",

"Property",

Value ");

In this method, first become a Digester object, then set the rules and callbacks, if you are not very familiar with XML, SAX is not very familiar, this is not necessary to entangle too deep. It should be noted that the addsetNext () method sets each of the SET NEXT callback methods to parse elements, and this method is provided by the father of the Digester parser. "AddmApping" in the top of the above is a method defined by the ActionServlet itself will be called by Digester. Digester is to store each FormBean, ActionForward, ActionMapping, etc. of the parsed, etc., forwards, mappings, and the like.

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

New Post(0)