This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes about EL Function Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "about EL Function" Watch "about EL Function" New topic
Author

about EL Function

Chang Tzu-yu
Greenhorn

Joined: Sep 17, 2007
Posts: 16
Hi,i try to use el function, but it doesn't work...
exception is :
symbol : class Test
location: class org.apache.jsp.TestEl_jsp
_jspx_fnmap_0= org.apache.jasper.runtime.ProtectedFunctionMapper.getMapForFunction("mine:getPet", Test.class, "getPet", new Class[] {java.lang.String.class});

.class:WEB-INF\classes\Test.class
12345678910111213
import java.util.HashMap;
import java.util.Map;

public class Test {
public static String getPet(String pKey){
Map tMapOut = new HashMap();
tMapOut.put("1","Cat");
tMapOut.put("2","Dog");
tMapOut.put("3","Monkey");

return (String)tMapOut.get(pKey);
}
}

JSP file:
<%@ taglib prefix="mine" uri="OAO" %>
${mine:getPet("3")}

.tld
<?xml version="1.0" encoding="UTF-8" ?>
<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>OAO</uri>
<function>
<name>getPet</name>
<function-class>Test</function-class>
<function-signature>
java.lang.String getPet(java.lang.String)
</function-signature>
</function>
</taglib>

thanks a lot!!


Chang Tzu-yu<br /> <br />SCJP 1.4
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Before looking further, I'd recommend you to put the Test class in a package.


[My Blog]
All roads lead to JavaRanch
Jan van Mansum
Ranch Hand

Joined: Oct 19, 2007
Posts: 74
I tried this out and it seems Christophe is right, if you put Test in a package it works, if you put it in the default package, it doesn't. (Using NetBeans 5.5.1 with Tomcat 5.5.17.)

Is this a servlet specs requirement (to put your classes in a package)? I couldn't find anything about it in the Servlet 2.4 document.


SCJP 1.4, SCWCD 1.4
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

JSP Specification, JSP.11.2 JSP Page Implementation Class

As of JSP 2.0, it is illegal to refer to any classes from the unnamed (a.k.a.default) package. This may result in a translation error on some containers,specifically those that run in a JDK 1.4 or greater environment. It is unfortunate,but unavoidable, that this will break compatibility with some older JSP applications. However, as of JDK 1.4, importing classes from the unnamed package is not valid (see http://java.sun.com/j2se/1.4/compatibility.html#source for details). Therefore, for forwards compatibility, applications must not rely on the unnamed package. This restriction also applies for all other cases where classes are referenced, such as when specifying the class name for a tag in a TLD.
Jan van Mansum
Ranch Hand

Joined: Oct 19, 2007
Posts: 74
Guess I was looking at the wrong document
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

I've found that even with non-web stuff that putting a class at the default level can mess things up. I don't even remember which IDE I was using, either NetBeans or Eclipse, but I got burned with frustrating errors enough to never try that again.


A good workman is known by his tools.
Chang Tzu-yu
Greenhorn

Joined: Sep 17, 2007
Posts: 16
dear all,
thanks a lot!!
it can work when i put it in a package!!!
 
Don't get me started about those stupid light bulbs.
 
subject: about EL Function
 
Similar Threads
Custom Tag
JSTL Syntax
JSP JSTL Custom Functions
Strange exception while using EL functions.
Custom EL Function problems