TLD or attribute directive in tag file, attribute value does not accept any expressions in JSP

When i run the following simple code in  eclipse with   App. Server Information : Apache Tomcat/7.0.26 , Sevlet Version : 3.0 ,  JSP Version : 2.1 and  Java Version : 1.6.0_20

  <c:forEach var="i" begin="1" end="50" step="1" >
   <c:out value="${i}"/ >
   </c:forEach >

I got the  error "According to TLD or attribute directive in tag file, attribute value does not accept any expressions" .  If you get the same error , making  the below changes in the JSP  will save your day.

 Replace the line       <%@ taglib uri='http://java.sun.com/jstl/core' prefix='c'% >   in the JSP  with    either      

       <%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c'% >              OR

         <%@ taglib uri='http://java.sun.com/jstl/core_rt' prefix='c'% >  

     
Let us see how the problem is solved .

Tag library descriptor (TLD)  files play major  role  because it  maps the tag and the tag handler class  . You need to just include taglib directive in the JSP with absolute URI  mentioned in the tld file  sothat the page can use

the tags defined in a tag library. TLD file has various attributes to be passed to the tag handler class.  One of the attribute is value  which accepts value or the expression to be evaluated depending upon the node

rtexprvalue (run time expression value)   value  as given below   <rtexprvalue >true </rtexprvalue >  . If it is true , it accepts , the expression , otherwise not.  Now let us see the reason.

Suppose you are using jstl-1.2.jar and standard-1.1.2.jar  , it has three .tld files for each library
 For example , core library  has  three tld files  (c-1_0.tld ,   c-1_0-rt.tld   ,  c.tld ) ,  format library has three tld files that are  fmt-1_0.tld ,   fmt-1_0-rt.tld   ,  fmt.tld .  Similary xml ,  sql


library have three tld files each , functions library has only one tld file.  You can see the tld files in the META-INF folder when you extract the jar files.

Now let us take the core library tld files c-1_0.tld ,   c-1_0-rt.tld   ,  c.tld . Each tld files have some changes . I have noticed  some of the changes .  Please gothrough the tld files given below which are related to

our problem

According to the old  c-1_0.tld , some of the specifications are as follows
 1.  attribute value does not accept any runtime expressions(rt)   ,  2. it uses DTD to define the  struture  of XML document ,  3 .it uses the  encoding  format "ISO-8859-1" ,  4. URI to  identify   the tag library

descriptor (TLD) file uniquely  is   http://java.sun.com/jstl/core    , 5. JSTL version 1.0   , 6. required JSP version  is 1.2

 Part of the tld file is given below



   <?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 >

  .........

.........

 <jsp-version >1.2 </jsp-version >

   <short-name >c </short-name >

   <uri >http://java.sun.com/jstl/core </uri >

   <description >JSTL 1.0 core library </description >



    <attribute >

         <name >value </name >

         <required >false </required >

         <rtexprvalue >false </rtexprvalue >   // false - does not accept rt expression

     </attribute >

.................... 

According to the   c-1_0-rt.tld file ,
 1.  attribute value accepts runtime expressions(rt)   ,  2. URI to  identify   the tag library descriptor (TLD) file is   http://java.sun.com/jstl/core_rt   , 3.  JSTL version 1.0   , 4.  required JSP version  is 1.2

 Part of the tld file is given below



 <?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" >



....

......

 <jsp-version >1.2 </jsp-version >

   <short-name >c_rt </short-name >

   <uri >http://java.sun.com/jstl/core_rt </uri >

   <display-name >JSTL core RT </display-name >

   <description >JSTL 1.0 core library </description >



 <attribute >

         <name >value </name >

         <required >false </required >

         <rtexprvalue >true </rtexprvalue >   // true - accepts rt expression

     </attribute >

......................

According to the  latest   c.tld   file ,
 1.  attribute value accepts any runtime expressions(rt)   ,  2. it uses XSD (XML Schema)   to define the  struture  of XML document ,  3. it uses the  encoding  format "UTF-8" ,  4. URI to  identify   the

tag library descriptor (TLD) file   is   http://java.sun.com/jsp/jstl/core    ,  5. data type is fixed for most of the variables which ensures the  type safe  , 5. JSTL version 1.1    , 6.  required JSP version is 2.0

Part of the tld file is given below



 <?xml version="1.0" encoding="UTF-8" ? >

 <taglib xmlns="http://java.sun.com/xml/ns/javaee"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee



http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"     version="2.1" >

.....

.....

 <description >JSTL 1.1 core library </description >

   <short-name >c </short-name >

   <uri >http://java.sun.com/jsp/jstl/core </uri >

.....



    <attribute >

         <description >

   Expression to be evaluated.

         </description >

         <name >value </name >

         <required >false </required >

         <rtexprvalue >true </rtexprvalue >

         <deferred-value >

      <type >java.lang.Object </type >

         </deferred-value >

     </attribute >

............... 


Now you have to decide which URI you have to use with taglib directive .

Summary to remember

JSTL 1.0  is compatible with : Servlet 2.3  ,  JSP 1.2  , suitable URI is  http://java.sun.com/jstl/core . To accept RT expression ,  use  http://java.sun.com/jstl/core_rt
 JSTL 1.1  is compatible with  Servlet 2.4  ,  JSP 2.0  , suitable URI is  http://java.sun.com/jsp/jstl/core . To work with old .tld file , use the URI   http://java.sun.com/jstl/core_rt
 JSTL 1.2  is compatible with  Servlet 2.5 onwards  ,  JSP 2.1 ,  suitable URI is  http://java.sun.com/jsp/jstl/core .Still you have chance to work with old .tld file  using the URI    http://java.sun.com/jstl/core_rt
 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.