One, the text label as an example
1. Configure
In Web.xml
<taglib>
<taglib-uri>/html</taglib-uri>
<taglib-location>/web-inf/ Struts-html.tld</taglib-location>
</taglib>
The use of 2.jsp
<%@ taglib uri= "/html" prefix= "html"%>
<tr id= "Auctionbidmodel" >
<td align= "right" >
<span class= "Fc-hong" >*</span> specification:
</td>
<td>
3. Switch to content via Struts label processor
<input type= "text" name= "Bean.bidmodel" value= "HHL" class= "Input-text" >
Second, look at its conversion process, source analysis
Basefieldtag.java
public int doStartTag () throws jspexception {/* <-MISALIGNED->/* 81*/Tagu
Tils.getinstance (). Write (Super.pagecontext, renderinputelement ());
/* <-MISALIGNED->/* 83*/return 2; } protected String Renderinputelement () throws jspexception {/* <-misaligned-& Gt */* 93*/stringbuffer results = new StringBuffer ("<input");/* 95*/Prepareattribute (results, "type",
Type);
/* 96*/Prepareattribute (results, "name", Preparename ());
/* 97*/Prepareattribute (results, "accesskey", Getaccesskey ());
/* 98*/Prepareattribute (results, "accept", getaccept ());
/* 99*/Prepareattribute (results, "maxlength", Getmaxlength ());
/* 100*/Prepareattribute (results, "size", getcols ());
/* 101*/Prepareattribute (results, "TabIndex", Gettabindex ());
/* 102*/Preparevalue (results); /* 103*/Results.append (prepareeventhAndlers ());
/* 104*/Results.append (Preparestyles ());
/* 105*/prepareotherattributes (results);
/* 106*/Results.append (Getelementclose ());
/* 107*/return results.tostring (); }
The main view of the value of the acquisition
protected void Preparevalue (StringBuffer results)
throws Jspexception
{
/* 116*/results.append (" Value=\ "");
/* 117*/ if (super.value!= null)/
* 118*/ results.append (Formatvalue (Super.value));
/* 120*/ else/* 120*/ if (redisplay | |!) Password ". Equals (type))
{/* 121*/ Object value = Tagutils.getinstance (). Lookup (Super.pagecontext, Super.name, super.property, null);
/* 124*/ results.append (Formatvalue (value));
}
/* 127*/ results.append (' ");
}
Lookup method, where name is name = "Org.apache.struts.taglib.html.BEAN";
Public Object Lookup (PageContext pagecontext, string name, String scopeName) throws Jspexception
{/* 887*/if (scopeName = null)/* 888*/return Pagecontext.findattribute (name); /* 892*/try {/* <-MISALIGNED->/* 892*/return Pagecontext.getattribute (name,
Instance.getscope (ScopeName)); }/* 895*/catch (jspexception e) {/* <-MISALIGNED->//* 895*/saveexception (page
Context, E);
/* <-MISALIGNED->/* 896*/throw E;
} public Object Lookup (PageContext pagecontext, string name, string, string scope) Throws Jspexception {/* 930*/Object bean = lookup (PageContext, name, scope);/* 931*/ if (bean = = null) {/* 932*/jspexception e = null;/* 933*/if (scope = null)/ * 934*/e =New Jspexception (Messages.getmessage ("Lookup.bean.any", name));
/* 936*/else/* 936*/e = new Jspexception (Messages.getmessage ("Lookup.bean", name, scope);
/* 940*/saveexception (PageContext, E);
/* 941*/throw E;
}/* 944*/if (property = = null)/* 945*/return bean; /* 950*/try {/* <-MISALIGNED->/* 950*/return Propertyutils.getproperty (bean
, property); }/* 953*/catch (illegalaccessexception e) {* * <-MISALIGNED-> * * 953*/SAVEEXCE
Ption (PageContext, E); /* <-MISALIGNED->/* 954*/throw new Jspexception (Messages.getmessage ("lookup.access", property, name)
); }/* 958*/catch (illegalargumentexception e) {/* <-MISALIGNED->///* 958*/Savee
Xception (PageContext, E); /* <-MISALIGNED->//* 959*/throw NEW jspexception (Messages.getmessage ("Lookup.argument", property, name)); }/* 963*/catch (invocationtargetexception e) {/* <-MISALIGNED->///* 963*/Thro
Wable t = e.gettargetexception (); /* <-MISALIGNED->/* 964*/if (t = = null)/* <-MISALIGNED->/* 965*/t = e;/* 9
67*/saveexception (PageContext, T);
/* 968*/throw new Jspexception (Messages.getmessage ("Lookup.target", property, name)); }/* 972*/catch (nosuchmethodexception e) {/* <-MISALIGNED->///* 972*/Saveex
Ception (PageContext, E);
}/* <-MISALIGNED-> * * 973*/throw new Jspexception (Messages.getmessage ("Lookup.method", property, name)); }
One of the most important beans to get
Object Bean = lookup (PageContext, name, scope);
Because scope is null, you go through the following process
if (ScopeName = null)/
* 888*/return pagecontext.findattribute (name);
where name is name = "Org.apache.struts.taglib.html.BEAN", then what is the BEAN obtained from this name, and the form label is required
Third, form label
1.jsp form label used
After the label processor becomes
<form name= "Storeproductform" method= "post" action= "/yunboce/store/manager/product/auctionproductadd.do" >
2. Look at the processing
Formtag.java
public int doStartTag ()
throws Jspexception
{/
* 443*/lookup ();
/* 446*/ stringbuffer results = new StringBuffer ();
/* 448*/ Results.append (Renderformstartelement ());
/* 450*/ Results.append (RenderToken ());
/* 452*/ tagutils.getinstance (). Write (Super.pagecontext, results.tostring ());
/* 455*/ Super.pageContext.setAttribute ("Org.apache.struts.taglib.html.FORM", this, 2);
/* 457*/ Initformbean (); Important processing of the above bean
/* 459*/return 1;
}
Look at the Initformbean method, which
protected void Initformbean () throws jspexception {/* 469*/int scope = 3;/* 470
*/if ("Request". Equalsignorecase (Beanscope))/* 471*/scope = 2;
/* 474*/Object bean = Super.pageContext.getAttribute (beanname, scope); /* 475*/if (bean = = null) {/* 477*/bean = requestutils.createactionform (httpservletre
Quest) Super.pageContext.getRequest (), mapping, Moduleconfig, servlet); /* 483*/if (bean instanceof actionform)/* 484*/((actionform) bean). Reset (Mapping, HTTPSERVLETR
equest) super.pageContext.getRequest ()); /* 486*/if (bean = = null)/* 487*/throw new Jspexception (Messages.getmessage ("Formtag.create")
Beantype));
/* 489*/Super.pageContext.setAttribute (beanname, bean, scope); }/* 491*/Super.pageContext.setAttribute ("Org.apache.struts.taglib.html.BEAN", BEAN, 2);
The above bean is added here }
So what is this bean, first look at the object bean = Super.pageContext.getAttribute (beanname, scope), and the parameter beanname, whose value is assigned in lookup
protected void Lookup () throws Jspexception {/* 738*/moduleconfig = tagutils.getins
Tance (). Getmoduleconfig (Super.pagecontext); /* 740*/if (moduleconfig = = null) {/* 741*/jspexception e = new Jspexception (MESSAGES.G
Etmessage ("Formtag.collections"));
/* 742*/Super.pageContext.setAttribute ("Org.apache.struts.action.EXCEPTION", E, 2);
/* 743*/throw E; }/* 745*/servlet = (actionservlet) super.pageContext.getServletContext (). getattribute ("Org.apache.struts.action.AC
Tion_servlet ");
/* 750*/String mappingName = Tagutils.getinstance (). Getactionmappingname (action);
/* 751*/mapping = (actionmapping) moduleconfig.findactionconfig (mappingName); /* 752*/if (mapping = = NULL) {/* 753*/jspexception e = new Jspexception (messages.getmes
Sage ("formtag.mapping", MappingName)); /* 754*/Super.pageContext.setAttribute ("org.aPache.struts.action.EXCEPTION ", E, 2);
/* 755*/throw E;
}/* 759*/formbeanconfig formbeanconfig = Moduleconfig.findformbeanconfig (Mapping.getname ()); /* 760*/if (formbeanconfig = = null) {/* 761*/jspexception e = new Jspexception (Messages
. GetMessage ("Formtag.formbean", Mapping.getname (), action));
/* 763*/Super.pageContext.setAttribute ("Org.apache.struts.action.EXCEPTION", E, 2);
/* 764*/throw E; else {/* 768*/Beanname = Mapping.getattribute ();
Beanname value, mapping to get/* 769*/Beanscope = Mapping.getscope ();
/* 770*/Beantype = Formbeanconfig.gettype ();
/* 771*/return; }
}
See here it should be understood that beanname is to get the properties in the mapping, whose values are configured in the Struts configuration file
<?xml version= "1.0" encoding= "UTF-8"?> <!
DOCTYPE struts-config Public "-//apache Software foundation//dtd struts Configuration 1.1//en" "http:// Jakarta.apache.org/struts/dtds/struts-config_1_1.dtd ">
<struts-config>
<data-sources> </data-sources>
<form-beans>
<form-bean name= "Storeproductform"
type= " Com.aebiz.store.product.controller.ProductForm "/>
</form-beans>
<global-forwards></ global-forwards>
<action-mappings>
<action input= "/store/manager/auctionproduct/ auctionproductadd.jsp "
name=" Storeproductform "path="/store/manager/product/auctionproductadd "
scope=" "Session"
type= "com.aebiz.store.auctionProduct.controller.AuctionProductAction" >
<forward name= "Add"
path= "/store/manager/auctionproduct/auctionproductadd.jsp"/>
</action>
</ Action-mappings>
</struts-config>
At this point, the bean used in the text label knows what it is (in this case productform), and value is
Propertyutils.getproperty (bean, property);
public static object GetProperty (Object bean, String name)
throws Illegalaccessexception, InvocationTargetException, nosuchmethodexception
{
/* 290*/return propertyutilsbean.getinstance (). GetProperty (bean, name);
public object GetProperty (object bean, String name)
throws Illegalaccessexception, InvocationTargetException, Nosuchmethodexception
{
/* 715*/return getnestedproperty (bean, name);
public object Getnestedproperty (object bean, String name) throws Illegalaccessexception, Invocationtarget Exception, nosuchmethodexception {/* 631*/if (bean = null)/* 632*/throw new Illegalargu
Mentexception ("No bean Specified");
/* 634*/if (name = = NULL)/* 635*/throw new IllegalArgumentException ("No name specified");
/* 638*/int indexofindexed_delim =-1;
/* 639*/int indexofmapped_delim =-1;
/* 640*/int indexofmapped_delim2 =-1;
/* 641*/int indexofnested_delim =-1; /* 643*/do {/* <-MISALIGNED->/* 643*/Indexofnested_delim = Name.indexof ('. ')
); /* <-MISALIGNED->///* 644*/Indexofmapped_delim = Name.indexof (');/* <-MISALIGNED->///* 645*
/indexofmapped_delim2 = Name.indexof (') '); /* <-MISALIGNED->/* 646*/if (indexofmapped_delim2 >= 0 && indexofmapped_delim >= 0&& (Indexofnested_delim < 0 | | indexofnested_delim > Indexofmapped_delim))/* 648*/Indexofnes
Ted_delim = Name.indexof ('. ', indexofmapped_delim2);
/* 651*/else/* 651*/indexofnested_delim = Name.indexof ('. ');
/* 653*/if (Indexofnested_delim < 0)/* 654*/break;
/* 656*/String next = name.substring (0, Indexofnested_delim);
/* 657*/Indexofindexed_delim = next.indexof (' [');/* 658*/Indexofmapped_delim = Next.indexof (' (');
/* 659*/if (bean instanceof map)/* 660*/bean = ((MAP) bean). get (next); /* 661*/else/* 661*/if (indexofmapped_delim >= 0)/* 662*/bean = Getmappedproper
Ty (bean, next); /* 663*/else/* 663*/if (indexofindexed_delim >= 0)/* 664*/bean = Getindexedprop
Erty (Bean, next); /* 666*/else/* 666*/bean = Getsimpleproperty (bean, next); /* 668*/if (bean = = null)/* 669*/throw new Nestednullexception ("Null property value for" + N
Ame.substring (0, Indexofnested_delim) + "'");
/* 673*/name = name.substring (Indexofnested_delim + 1);
} while (true);
/* 676*/Indexofindexed_delim = name.indexof (' [');/* 677*/Indexofmapped_delim = Name.indexof (' (');
/* 679*/if (bean instanceof map)/* 680*/bean = ((MAP) bean). get (name); /* 681*/else/* 681*/if (indexofmapped_delim >= 0)/* 682*/bean = getmappedproperty (Bean, NAM
e); /* 683*/else/* 683*/if (indexofindexed_delim >= 0)/* 684*/bean = getindexedproperty (Bean, n
AME); /* 686*/else/* 686*/bean = getsimpleproperty (bean, name);
Final use of reflection to get value/* 688*/return bean; }
Where there is the processing of the dot character, and so on, get the value of the bean to get the value of the property, so the Bean.bidmodel value of the original tag gets the
public object Getsimpleproperty (object bean, String name) throws Illegalaccessexception, Invocationtargete Xception, Nosuchmethodexception {/*1088*/if (bean = = null)/*1089*/throw new Illegalargum
Entexception ("No bean Specified");
/*1091*/if (name = = null)/*1092*/throw new IllegalArgumentException ("No name specified"); /*1096*/if (Name.indexof ('. ') >= 0)/*1097*/throw new IllegalArgumentException ("Nested Property name
s are not allowed "); /*1099*/if (Name.indexof (' [') >= 0)/*1100*/throw new IllegalArgumentException ("Indexed Property nam
Es are not allowed "); /*1102*/if (Name.indexof (') >= 0)/*1103*/throw new IllegalArgumentException ("mapped property name
s are not allowed ");
PropertyDescriptor descriptor; /*1108*/if (bean instanceof Dynabean) {/*1109*/descriptor = ((Dynabean) bean). Getdynacla ss). Getdynaproperty (name); /*1111*/if (descriptor = null)/*1112*/throw new Nosuchmethodexception ("Unknown Property" +
Name + "'");
/*1115*/else/*1115*/return ((Dynabean) beans). get (name);
}/*1119*/Descriptor = Getpropertydescriptor (bean, name); /*1121*/if (descriptor = = null)/*1122*/throw new Nosuchmethodexception ("Unknown Property" + Name + "
'");
/*1125*/Method Readmethod = Getreadmethod (descriptor); /*1126*/if (Readmethod = = null) {/*1127*/throw new Nosuchmethodexception ("property" +
Name + "' has no Getter method"); else {/*1132*/Object value = InvokeMethod (Readmethod, Bean, new object[0);/*1133*/
return value; }
}