| Author |
.tld error
|
Deepinder S Narang
Greenhorn
Joined: Sep 05, 2006
Posts: 21
|
|
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.
|
 |
Srinivasan thoyyeti
Ranch Hand
Joined: Feb 15, 2007
Posts: 557
|
|
Hi, The XSD version is preferred since JSP 2.0 / Servlets 2.4 (eg: Tomcat 5.5). Please check that.
|
Thanks & Regards,<br />T.Srinivasan,<br />SCWCD 1.4(89%),SCJP 5.0(75%)<br />"That service is the noblest which is rendered for its own sake." - Mahatma Gandhi
|
 |
Johan Pelgrim
Ranch Hand
Joined: Jul 07, 2003
Posts: 105
|
|
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 ]
|
Johan Pelgrim, The Netherlands
SCJP 1.4, SCWCD 1.4, SCBCD 5.0
|
 |
Srinivasan thoyyeti
Ranch Hand
Joined: Feb 15, 2007
Posts: 557
|
|
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
Joined: Jul 07, 2003
Posts: 105
|
|
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?
|
 |
Tridib Samanta
Ranch Hand
Joined: Apr 28, 2004
Posts: 128
|
|
<function-signature> void getDbname </function-signature>
try this: <function-signature> int getRandomnumber() </function-signature> [ March 20, 2007: Message edited by: Tridib Samanta ]
|
Thanks, Tridib
SCJP 1.4, SCWCD 1.4, SCBCD 5.0
|
 |
Johan Pelgrim
Ranch Hand
Joined: Jul 07, 2003
Posts: 105
|
|
Tridib, You're so right... I forgot the brackets... Copy-paste error... (fixed it in my post if anybody is copy-pasting that
|
 |
Manju Devarla
Ranch Hand
Joined: Dec 14, 2006
Posts: 85
|
|
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" ; } }
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14672
|
|
Manju, try correct the following : <?xml version="1.0" encoding="ISO-8859-1" ?>
|
[My Blog]
All roads lead to JavaRanch
|
 |
warren li
Ranch Hand
Joined: May 23, 2006
Posts: 128
|
|
|
also, don't forget the <short-name> in the tld. It is mandatory.
|
SCBCD 1.3: 94%<br />SCWCD 1.4: 91%<br />SCJP 5: 95%
|
 |
Manju Devarla
Ranch Hand
Joined: Dec 14, 2006
Posts: 85
|
|
|
Thanks Satou ..Finally got it.. :-)
|
 |
Deepinder S Narang
Greenhorn
Joined: Sep 05, 2006
Posts: 21
|
|
Thanks a lot guys it's workin ! Was out of town ....... that's why sending delayed reply
|
 |
Clifton Eaton
Greenhorn
Joined: Mar 26, 2007
Posts: 16
|
|
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
|
-------------------------------------<br />SCJP<br />SCWCD
|
 |
Johan Pelgrim
Ranch Hand
Joined: Jul 07, 2003
Posts: 105
|
|
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
Joined: Mar 26, 2007
Posts: 16
|
|
|
Interesting. I got that information from Sun's J2EE tutorial. I just checked the jsp spec and it does seem to be required.
|
 |
 |
|
|
subject: .tld error
|
|
|