Java 调用自定义Apache Velocity EventHandler错误
因此,我正在努力创建一个自定义EventHandler,以便在ApacheVelocity中跨我的网站转义(以及更多)HTML变量和参数。我尝试过使用默认的转义工具(EscapeHtmlReference、EscapeSqlReference等),但它们并不适合我的所有需要 因此,我基于org.apache.velocity.app.event.implement.EscapeSqlReference创建了自己的EventHandler,但每次尝试调用它时,都会出现一个强制转换错误 我创建的新类:Java 调用自定义Apache Velocity EventHandler错误,java,velocity,Java,Velocity,因此,我正在努力创建一个自定义EventHandler,以便在ApacheVelocity中跨我的网站转义(以及更多)HTML变量和参数。我尝试过使用默认的转义工具(EscapeHtmlReference、EscapeSqlReference等),但它们并不适合我的所有需要 因此,我基于org.apache.velocity.app.event.implement.EscapeSqlReference创建了自己的EventHandler,但每次尝试调用它时,都会出现一个强制转换错误 我创建的新类
public class EscapeXmlPlusReference extends EscapeReference
{
/**
* Escape all XML entities plus ;.
*
* @param text
* @return An escaped String.
* @see <a href="http://jakarta.apache.org/commons/lang/api/org/apache/commons/lang/StringEscapeUtils.html#escapeSql(java.lang.String)">StringEscapeUtils</a>
*/
protected String escape(Object text)
{
return StringEscapeUtils.escapeXml(text.toString().replace(";",""));
}
/**
* @return attribute "eventhandler.escape.xmlplus.match"
*/
protected String getMatchAttribute()
{
return "eventhandler.escape.xmlplus.match";
}
}
但是每次我加载一个页面,我都会得到一个强制转换异常
Velocity [error] Could not initialize VelocityEngine - java.lang.ClassCastException: gov.location.of.class.security.vtool.EscapeXmlPlusReference cannot be cast to org.apache.velocity.app.event.EventHandler
有什么小东西我遗漏了吗?看起来这里涉及到了类加载问题。也许类路径中有几个velocity副本。
Velocity [error] Could not initialize VelocityEngine - java.lang.ClassCastException: gov.location.of.class.security.vtool.EscapeXmlPlusReference cannot be cast to org.apache.velocity.app.event.EventHandler