Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Using TLD in JSP

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//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,
 
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Tomcat 5.5,Servlet 2.4
 
CAUTION! Do not touch the blades on your neck propeller while they are active. Tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic