• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

.tld error

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello friends ....

my below mentioned tld file

<?xml version="1.0" encoding="ISO-8859-1" ?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" version="2.0">
<tlib-version> 1.2 </tlib-version>
<uri> DataBaseName </uri>
<function>
<name> getRandomnumber </name>
<function-class> com.example.model.Random </function-class>
<function-signature> void getDbname </function-signature>
</function>
</taglib>

gives the following error

org.apache.jasper.JasperException: Unable to initialize TldLocationsCache: XML parsing error on file /WEB-INF/myFunction.tld: (line 2, col 6)
org.apache.jasper.compiler.TldLocationsCache.init(TldLocationsCache.java:249)
org.apache.jasper.compiler.TldLocationsCache.getLocation(TldLocationsCache.java:220)
org.apache.jasper.JspCompilationContext.getTldLocation(JspCompilationContext.java:475)
org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:417)
org.apache.jasper.compiler.Parser.parseDirective(Parser.java:483)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1539)
org.apache.jasper.compiler.Parser.parse(Parser.java:126)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:220)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:101)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:203)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:470)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

for the following class

package com.example.model;
public class Random{
int randomnumber;
public static int getRandomnumber(){
return (int) (Math.random() * 100);
}

}

Please help !

Thanks.
 
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

The XSD version is preferred since JSP 2.0 / Servlets 2.4 (eg: Tomcat 5.5).

Please check that.
 
Ranch Hand
Posts: 105
Android Mac Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
FYI I use this taglib tag and attributes:



Furthermore it looks like your function-signature definition is incorrect:

It should be


P.S. A suggestion is to use better CamelCasing for your method name, i.e. getRandomNumber instead of getRandomnumber (see CamelCase on WikiPedia)

[ March 20, 2007: Message edited by: Johan Pelgrim ]
[ March 20, 2007: Message edited by: Johan Pelgrim ]
 
Srinivasan thoyyeti
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Johan,

Good Catch.

But
org.apache.jasper.JasperException: Unable to initialize TldLocationsCache: XML parsing error on file /WEB-INF/myFunction.tld: (line 2, col 6)

do not point your catch.

what you say.
 
Johan Pelgrim
Ranch Hand
Posts: 105
Android Mac Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Srinivasan,

True true... but then again, that exception was probably thrown on executing the accompanying jsp-page that Deepinder didn't include... (probably on a wrong taglib directive?!) So I only commented on what I saw (and which I hope will fix it for Deepinder)... Deepinder? Do our comments help? If not could you post your jsp-page, which should contain a taglib directive to your custom tag library?
 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

<function-signature> void getDbname </function-signature>



try this:

<function-signature> int getRandomnumber() </function-signature>
[ March 20, 2007: Message edited by: Tridib Samanta ]
 
Johan Pelgrim
Ranch Hand
Posts: 105
Android Mac Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tridib,

You're so right... I forgot the brackets... Copy-paste error... (fixed it in my post if anybody is copy-pasting that
 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Deepender,

I am facing the same problem ..
Could you tell me how did you resolve this ..


Unable to initialize TldLocationsCache: XML parsing error on file /WEB-INF/myFun.tld: (line 1, col 20)
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

Aswell as foloowing error

org.apache.jasper.JasperException: Unable to load class for JSP
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


Even myFul.tld is correct with function signature

<?xml vesrion="1.0" encoding="ISO-8859-1" ?>

<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" version="2.0">

<tlib-version>1.2</tlib-version>

<uri>DiceFunctions</uri>

<function>
<name>rollIt</name>
<function-class>foo.DiceRoller</function-class>
<function-signature> String rolldice()</function-signature>
</function>

</taglib>


and this is my jsp file..

<%@ taglib prefix="mine" uri="DiceFunctions" %>

<html>
<body>

${mine:rollIt()}

</body>
</html>

Class code :

package foo;
public class DiceRoller {

public static String rolldice() {

return "suguna" ;
}
}
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Manju,
try correct the following :
<?xml version="1.0" encoding="ISO-8859-1" ?>
 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
also, don't forget the <short-name> in the tld. It is mandatory.
 
Manju Devarla
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Satou ..Finally got it.. :-)
 
Deepinder S Narang
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot guys it's workin !

Was out of town ....... that's why sending delayed reply
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by warren li:
also, don't forget the <short-name> in the tld. It is mandatory.



According to this source, the <short-name> tag is optional:

http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSPTags6.html
 
Johan Pelgrim
Ranch Hand
Posts: 105
Android Mac Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Clifton ... only one way to find out... I tried leaving it out and run my web app. Indeed it is working fine (in Tomcat) without the short-name! I'd still say the spec (XSD) is correct and it's mandatory (and Tomcat's implementation of the spec is wrong)... So whenever that question pops up on the exam I'll say it's mandatory
 
Clifton Eaton
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Interesting. I got that information from Sun's J2EE tutorial. I just checked the jsp spec and it does seem to be required.
reply
    Bookmark Topic Watch Topic
  • New Topic