- 论坛徽章:
- 0
|
谁能说说用tag file的理由。我没看出来有什么好处,反而比用普通tag或者EL要麻烦得多,要拐好多弯。
比如,如果里面的逻辑必须要用Java实现时(也就是说用用JSTL或者标准EL实现不了时),那么还是要创建一个自定义的tag或者EL函数,因为在tag file里又不能用scriptlet。那么我为什么不直接在我的JSP文件里用自定义的tag或者EL函数?为什么要将它提出来放到单独的tag file里呢?
下面是引用一本书里的:
The tag file needs to find its own way of substituting the Java logic otherwise placed in
the doTag() method of a genuine simple tag handler class. Actual Java logic is
disallowed: A tag file chokes as soon as you try to introduce the smallest of Java
language scriptlets. Instead, you use custom actions, and you are especially likely to
choose actions from the JSTL.
What if there is logic that is beyond the bounds of what JSTL and EL can
accomplish? Well, you can always access “real Java” by means of a (real) custom
tag (not a tag file) used within the tag file. Or, as this example shows, through
an EL function. |
|