问题一:
TLD文件中,如下:
<tag>
<name>putList</name>
<tagclass>org.apache.struts.taglib.tiles.PutListTag</tagclass>
<bodycontent>JSP</bodycontent>
<attribute>
<name>name</name>
<required>true</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
</tag>
其中的<bodycontent>,<required>和<rtexprvalue> 是什么意思?
问题二:
我定义了一个tag类,定义如下:
package com.ufida.view.tag;import javax.servlet.http.HttpSession;
import javax.servlet.jsp.tagext.TagSupport;import com.ufida.constansts.GlobalConst;public class GetGlobalParameTag  extends TagSupport{
public String getUserId()
{
HttpSession myhttpsession = pageContext.getSession();
if (myhttpsession == null)
return "";
String userId = (String)myhttpsession.getAttribute(GlobalConst.USERCODE_KEY);
if (userId == null)
return "";
userId = userId.trim();
return userId;
}

}
在tld文件中要怎么定义?

解决方案 »

  1.   

    <bodycontent>指的是<putList></putList>中间的代码,你定义的类型是jsp,也就是你的标签<putList></putList>中间放置的是jsp代码;
    <required>是你定义的标签的属性name是否一定要,true表示该属性不能缺少;
    <rtexprvalue>表示你的name属性的值如何处理,
         false是只能按照text文本数据处理;true表示name的值可以是表达式.
      

  2.   

    你写的GetGlobalParameTag也有问题,一般tag要Override两个方法,doStartTag()和doEndTag();
    如果标签复杂的话还要Override别的方法,如迭代等;
    在doStartTag()中初始化标签;在doEndTag()处理<bodycontent>中的内容,如果没有<bodycontent>,这个方法不需要,直接在doStartTag()处理即可.
    详细的写法你自己参考相关资料,上面一般都很详细~
      

  3.   

    <bodycontent>
    是标签体中的代码<required>
    如果为true 代表这个属性是必须的 如果为false 代表这个属性可有可无<rtexprvalue> 
    如果为true 可以使用表达式 如果为false 不可以使用
      

  4.   

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" 
     "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
    <taglib>
    <tlib-version>1.2</tlib-version>
    <jsp-version>1.1</jsp-version>
    <short-name>page</short-name>
    <uri>http://struts.apache.org/tags-page</uri>
    <tag>
    <name>page</name>
    <tag-class>com.thinkbank.page.PageTag</tag-class>  //这里对应你的自定义类
    <attribute>
    <name>url</name>
    <required>true</required>
    <rtexprvalue>true</rtexprvalue>
    </attribute>
    <attribute>
                    ...
                    </attribute>
    </tag>
    </taglib>
    最后需要将这个tld文件在web.xml中设置一下如下,然后你就可以在jsp中引用它了
    <taglib>
            <taglib-uri>http://jpager.com/taglibs/page</taglib-uri>
            <taglib-location>/WEB-INF/jpager.tld</taglib-location>
    </taglib>