Well, we always like to customize some nouns, where "label scope" means that the scope of a variable is only within the tag, and the value is not obtained outside the label.
The effect of labeling requirements is as follows:
JSP page:
... <cms:category var= "Cate" ...> column name: ${cate.name} column Article list:<c:foreach var= "item" items= "${ Cate.articlelist} ">${item.name}<br/></c:forEach></cms:category>...
HTML pages that are printed after compilation:
... Column Name: News column column article list: News news Two news three ...
<cms:category> is a custom tag whose content is to get database data and then upload it to a JSP page
There are several ways to transfer from custom tags to JSP pages
Note: The JSP has 4 scopes, the smallest of which is page
And here I want the effect to be a bit similar to returning a "local variable"
This variable is only available in the tag (with a value) and is unavailable outside the label, with the following effect:
<cms:category var= "Cate" >
${cate} ==>> has value
</cms:category>
${cate} ==>> No value
At first I thought of this effect similar to the JSTL standard library <c:forEach> tag iteration values are only valid within the tag, and are similar to "local variables" from the JSP perspective
So I created a new Java-web test project, but did not find the corresponding method to set the "local variables" (here also silly spent a lot of time to check information, debugging, Combat)
So I decided to check the <c:forEach> tag source code, found Looptagsupport class will go to implement a trycatchfinally interface
In fact, the principle is very simple, from the interface name can be seen from a little bit of mystery it (here, the heart monologue is "CNMMD, the original is so")
In fact, there is no way to set "local variables"
You can use the Pagecontext.setattribute () method to return a value in a label, but the return value is the page scope
After implementing the Trycatchfinally interface there will be a dofinally method that will be called after Doendtag ()
Then the <c:forEach> tag is the Dofinally method that uses Pagecontext.removeattribute () to destroy the return value.
Well, the smart little buddy here should know how it's done.
Well, if there is a wrong place, please correct me, thank you for checking.
Java EE Custom Tags: implementing label scopes