Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Using TLD in JSP" Watch "Using TLD in JSP" New topic

Using TLD in JSP

Bulent Kamberoglu

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

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

//myFunctions.tld under WEB-INF

<taglib xmlns="" version="2.0">
int rollDice()


// 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=""

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

<!-- JSPC servlet mappings start -->


<!-- JSPC servlet mappings end -->


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.

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

Joined: Jul 06, 2005
Posts: 1580
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

Joined: Aug 14, 2005
Posts: 6
I am using Tomcat 5.5,Servlet 2.4
I agree. Here's the link:
subject: Using TLD in JSP
It's not a secret anymore!