Dúvida com EL functions - exceção

4 respostas
Roger75

Olá,

Estou tentando fazer um exemplo do "Head First Servlets & JSP" de functions com EL mas está dando um erro ao visualizar minha JSP.

A JSP está assim:

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

${mine.rollIt()}

</body></html>

A TLD myFunctions.tld está assim:

<?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-app_2_4.xsd" 
          version="2.4">
<tlibversion>1.0</tlibversion>
<jsp-version>1.2</jsp-version>
<uri>DiceFunctions</uri>
	<function>
		<name>rollIt</name>
		<function-class>pacote.DiceRoller</function-class>
		<function-signature>
			int rollDice()
		</function-signature>
	</function>


</taglib>
e a TLD está no WEB-INF

A classe DiceRoller está assim:

package pacote;



public class DiceRoller{
	public static int rollDice(){
		return (int) ((Math.random()*6)+1);
	}
}
O erro que aparece ao visualizar a JSP é o seguinte:
org.apache.jasper.JasperException: /head_first_pg389.jsp(4,2) The function rollIt must be used with a prefix when a default namespace is not specified
	org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:83)
	org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:402)
	org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:186)
	org.apache.jasper.compiler.Validator$1FVVisitor.visit(Validator.java:1272)
	org.apache.jasper.compiler.ELNode$Function.accept(ELNode.java:163)
....

4 Respostas

Rafael_Nunes

A chamada para EL functions é como uma taglib:

${mine:rollIt()}
Roger75

Rafael Nunes:
A chamada para EL functions é como uma taglib:

${mine:rollIt()}

E não foi isso que eu fiz?

Rafael_Nunes

Segundo o código que você postou, não.

mine:rollit (dois pontos)

e não mine.rollIt(ponto)

Roger75

É verdade, eu tinha colocado “.” ao invés de “:”.
Valeu!

Criado 18 de julho de 2006
Ultima resposta 18 de jul. de 2006
Respostas 4
Participantes 2