Labels

.NET Job Questions About Java Absract class Abstract class Abstract Class and Interface Aggregation ajax aop apache ofbiz Apache ofbiz tutrial Association authentication autocad basics batch Binary Tree bootstrap loader in java build Builder design pattern C++ Job Questions caching CallableStatement in java certifications Chain of responsibility Design pattern charts check parentheses in a string Classes classloader in java classloading concept code quality collage level java program Composition concurrency Concurrency Tutorial Converting InputStream to String Core Java core java concept core java interview questions Core Java Interview Questions Core Java Questions core java tutorial CyclicBarrier in Java data structures database Database Job Questions datetime in c# DB Db2 SQL Replication deserialization in java Design Patterns designpatterns Downloads dtd Eclipse ejb example/sample code exception handling in core java file handling injava File I/O vs Memory-Mapped Filter first program in spring flex Garbage Collection Generics concept in java grails groovy and grails Guice Heap hibernate Hibernate Interview Questions how-to IBM DB2 IBM DB2 Tutorial ide immutable Interceptor Interface interview Interview Questions for Advanced JAVA investment bank j2ee java JAVA Code Examples Java 7 java changes java class loading JAVA Classes and Objects Java Classloader concept Java classloading concept java cloning concept java collection Java collection interview questions Java Collections java concurrency Java CountDownLatch java definiton Java design pattern Java EE 5 Java EE 6 Java Exceptions Java file Java Garbage Collection Java generics Java Glossary java hot concept java immutable concept Java Interface Java interview Question java interview question 2012 java interview question answer Java Interview Questions Java Interview Questions and Answers java interview topic java investment bank Java Job Questions java multithreading java multithreading concept java new features Java Packages java proxy object java questions Java Serialization Java serialization concept java serialization interview question java session concept java string Java Swings Questions java synchronization java threading Java Threads Questions java tutorial java util; java collections; java questions java volatile java volatile interview question Java Wrapper Classes java.java1.5 java.lang.ClassCastException JavaNotes javascript JAX-WS jdbc JDBC JDBC Database connection jdk 1.5 features JDK 1.5 new features Concurrent HashMap JMS interview question JMS tutorial job JSESSIONID concept JSESSIONID interview Question JSF jsp JSP Interview Question JSP taglib JSTL with JSP Junit Junit Concept Junit interview question.Best Practices to write JUnit test cases in Java JVM Linux - Unix tutorial Marker Interfaces MD5 encryption and decryption messaging MNC software java interview question musix NCR java interview question Networking Job Questions news Object Serialization Objects ojdbc14.jar OOP Oracle Oracle SQL Query for two timestamp difference orm own JavaScript function call in Apache ofbiz Packages Palm Apps patterns pdf persistence Portal Portlet Spring Integration Prime number test in java programs Rails Reboot remote computers REST Ruby Sample application schema SCJP security Senior java developer interviews servlet3 servlets session tracking singleton design pattern Spring Spring 2.5 Framework spring ebook Spring framework concept spring MVC spring pdf Spring Security Spring Security interview questions SQL SQL performance SQL Query to create xml file Sql Query tuning ssis and ssrs StAX and XML string concept string immutable string in java strings struts Struts2 Struts2 integration synchronization works in java Technical Interview testing tips Tomcat top Tutorial Volatile in deep Volatile working concept web Web Developer Job Questions web services weblogic Weblogic Application Server websphere what is JSESSIONID xml XML parsing in java XML with Java xslt


Monday 8 July 2013

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

LinkWithin

Related Posts Plugin for WordPress, Blogger...