Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes IDEs, Version Control and other tools and the fly likes how to create tld file? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "how to create tld file?" Watch "how to create tld file?" New topic
Author

how to create tld file?

Bobby Sharma
Ranch Hand

Joined: Mar 18, 2008
Posts: 591
    
    1

Eclipse IDE for j2ee 3.x
Tomcat 6.x
Java 6
Hi friends I have problem regarding tld.
I have following files.


//a.tld file

//jsp file : Test.jsp


When I test the jsp file I get this errorrg.apache.jasper.JasperException: /Test.jsp(6,2) The function rolldice cannot be located with the specified prefix

I doubt that I am wrong in creating tld.By the way I did not create web.xml
for this project since the book(HFSJ SCWCD 1.4) does not tell me to do so.
Head First Servlet and Jsp(ch 8,page 389).


Most of the programming problems can't be solved because you don't know what the exact problem is.
Defining your problem correctly leads you to the right solution.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

I doubt that I am wrong in creating tld.

What about your "function-singnature" tag ? ;) I've never heard of the "funtion" tag either. And it looks like "uri" is not where it should be. I doubt that this TLD is correct
[ March 24, 2008: Message edited by: Christophe Verre ]

[My Blog]
All roads lead to JavaRanch
Bobby Sharma
Ranch Hand

Joined: Mar 18, 2008
Posts: 591
    
    1

LOL, got it. I should have noticed. :p

thanks

best regards
omi
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 62317
    
  68

Originally posted by Christophe Verre:
I've never heard of the "funtion" tag either.
It's the means by which EL functions are declared.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

It's the means by which EL functions are declared.

It was intended to be a joke ;) There's a spell miss in the tag name : "funtion" -> "function"
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 62317
    
  68

Whoooooooooooosh!

(sound of joke whizzing past Bear's oblivious head)
Hasif Subair
Greenhorn

Joined: Aug 12, 2009
Posts: 24
I am getting the output of this program as 1, no matter how many times i run, wasn't supposed to be random numbers between 1 to 6.....
James Wiggins
Greenhorn

Joined: Feb 09, 2010
Posts: 1
Yes, you will always get "1" output because...

return ((int)Math.random()*6+1);

...should be...

return ((int)(Math.random()*6)+1);


James Wiggins
www.iwiggins.com
pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 323

Hello All,

I did the same, but no luck for me.

I have Eclipse EE. Tomcat 6.0.

Below is the program : -

DiceRoller class for static function:

package foo;

public class DiceRoller {

public static int rollDice()
{
return (int) ((Math.random() * 6) + 1);
}

}

------------

MyFunctions.tld --- I placed this file under WEB-INF

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

<taglib version="2.0">

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

<uri>DiceFunction</uri>
<function>
<name>rollIt</name>
<function-class>foo.DiceRoller</function-class>
<function-signature>int rollDice()</function-signature>
</function>

</taglib>

------------------------------

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="mine" tagdir="/WEB-INF/myFunction.tld" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

${mine:rollIt() }

</body>
</html>

-------------------

index.html as welcome page :

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="Result.jsp" method="get">
Go

<input type="submit"></input>

</form>

</body>
</html>

-------------------------

I'm getting this error at runtime :
org.apache.jasper.JasperException: File "/DiceFuntion" not found


Eclipse highlights uri="DiceFuntion" as can not find the tag library descriptor , hence there is error for ${mine:rollIt()} as well.


While I found one of the IDE(name is not given) offering a template to create .tld file, I had to create on XML under New-Other and change the extension from .xml to .tld

Please please help.
Many thanks.

Pramod


Thanks,
Pramod
pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 323

Oops, the code works fine when I make this change :

<%@ taglib prefix="mine" uri="/WEB-INF/myFunctions.tld" %>

The problem is that <%@ taglib prefix="mine" tagdir="/WEB-INF/myFunctions.tld" %> this code shows the below error

org.apache.jasper.JasperException: Tag file directory /WEB-INF/myFunctions.tld does not start with "/WEB-INF/tags"

I guess tagdir is not the right keyword for this as error code is showing tags directory which I assume, we use for .tag files.

Please advise.

Many thanks.
pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 323

Hello Again,

I'm trying to use <cut> tags in jsp & getting this runtime error
org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application

Below is the code :

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>ReSuLT</title>
</head>
<body>

This is list

<cut value="movielist"></cut>

</body>
</html>

-------------------
The configuration is Tomcat 6.0, Eclipse EE 3.5.2, WebApp version 2.4
When I didn't add jstl.jar & standard.jar , Eclipse displayed unknown tag <cut>

So i added both jar files to Build path/Libraries and CLASSPATH variable.
My friend suggested to me to check if both jars are present in Webapps folder for which I got this :
C:\Tomcat6\apache-tomcat-6.0.29\webapps\examples\WEB-INF\lib\jstl.jar and stanard.jar

I haven't defined anything in web.xml.

Please advise.

Many Thanks,

pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 323

I added two entries to web.xml but same problem is showing up again.

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" 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 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:fmt="http://java.sun.com/jsp/jstl/fmt">

<display-name>JSTL</display-name>

<servlet>
<description>
</description>
<display-name>Check</display-name>
<servlet-name>Check</servlet-name>
<servlet-class> test.Check</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Check</servlet-name>
<url-pattern>/Check</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>

</welcome-file-list>


</web-app>
pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 323

Hello All,

The issue is solved

Actually, I had to copy two jars jstl.jar and standard.jar from C:\Tomcat6\apache-tomcat-6.0.29\webapps\examples\WEB-INF\lib to C:\Tomcat6\apache-tomcat-6.0.29\lib

Thank you.

Pramod
 
 
subject: how to create tld file?