aspose file tools*
The moose likes JSP and the fly likes Using TLD in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Using TLD in JSP" Watch "Using TLD in JSP" New topic
Author

Using TLD in JSP

Bulent Kamberoglu
Greenhorn

Joined: Aug 14, 2005
Posts: 6
//JSP file

<%@ taglib prefix="mine" uri="DiceFunctions"%>
<html><body>
${mine:rollIt()}
</body></html>

//myFunctions.tld under WEB-INF

<taglib xmlns="http://java.sun.com/xml/ns/j2ee" version="2.0">
<tlib-version>1.2</tlib-version>
<uri>DiceFunctions</uri>
<function>
<name>rollIt</name>
<function-class>DiceRoller</function-class>
<function-signature>
int rollDice()
</function-signature>
</function>

</taglib>

// DiceRoller.java under WEB-INF\classes
import java.util.*;
public class DiceRoller{
public static int rollDice(){
return (int) ((Math.random() * 6) + 1);
}
}

// web.xml under WEB-INF

<web-app 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"
version="2.4">

<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>

<!-- JSPC servlet mappings start -->

<servlet>
<servlet-name>TestBean</servlet-name>
<jsp-file>/Test3/TestBean.JSP</jsp-file>
</servlet>
<jsp-config>
<taglib>
<taglib-uri>DiceFunctions</taglib-uri>
<taglib-location>/WEB-INF/myFunctions.tld</taglib-location>
</taglib>
</jsp-config>


<!-- JSPC servlet mappings end -->

</web-app>

I also add jstl.jar in my WEB-INF/lib directery.But still this program does not work.As output I get only ${mine:rollIt()}.In my computer I can not run EL .I always get same result ${....} ,no output.Could you tell me how i can fix this problem?Thanks in advance.

Cheers,
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
Add this page directive at the beginning of the JSP Page
<%@ page isELIgnored="false" %> for EL to work

You should add one more element in your TLD file <short-name>mine</shot-name>.
You can use short-name to refer prefix attribute of taglib directive.


AND you don't have to add all these in your web.xml file.



AND make sure you complete your <sevlet-mapping> element



Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
The only thing I can see wrong is that your java code must be in a package.

Seeing as you have specified your web.xml as version 2.4, EL evaluation should be enabled by default.
What server are you using? Is it Servlet2.4/JSP2.0 capable? (eg Tomcat 5)
Bulent Kamberoglu
Greenhorn

Joined: Aug 14, 2005
Posts: 6
I am using Tomcat 5.5,Servlet 2.4
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using TLD in JSP