日期:2014-05-18  浏览次数:20617 次

使用JSTL自定义标签 属性值如何得到EL表达式的值?
我现在使用的是JSTL1.O,因为必须使用JSTL1.0,所以很多1.1和1.2的功能都不能支持,郁闷死了

现在我只有自己写了一个标签扩展JSTL1.0的功能  
java代码如下:
  public   int   doStartTag()   throws   JspException   {
              JspWriter   out   =   pageContext.getOut();
              try{
                      if(str   ==   null||str.trim().length()   ==   0){
                              out.print( "  ");
                                              }
                      else{
                              out.print(str);
                      }

              }catch(Exception   e){
                      e.printStackTrace();
              }
              return(SKIP_BODY);

      }


tld文件如下:
<?xml   version= "1.0 "   encoding= "ISO-8859-1 "   ?>
<!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.0 </tlib-version>
    <jsp-version> 1.2 </jsp-version>
    <short-name> my </short-name>
    <uri> http://bravejj.com/jstl/MyTaglib </uri>
    <display-name> showfield </display-name>
    <description> Custom   Tag   Library </description>

    <tag>
    <name> sf </name>
    <tag-class> com.bravejj.jstlfuction.showfield </tag-class>
    <body-content> empty </body-content>

    <attribute>
    <name> str </name>
    <required> true </required>
    <rtexprvalue> true </rtexprvalue>
    </attribute>

    </tag>
    </taglib>

jsp页面:
<body   bgcolor= "#ffffff ">
<h1>
test   mytag   sf
</h1>
<my:sf   str= "                     "/>
<br   />
<c:set   var= "jj "   value= "test "/>
<c:out   value= "${jj} "/>
<br   />

<my:sf   str= "jj "/>
</body>

我的问题是想在页面上把变量jj的值通过EL表达式传给my:sf   标记的属性str
就像 <c:out