有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java调用自定义Apache Velocity事件处理程序错误

因此,我正在努力创建一个自定义EventHandler,以便在ApacheVelocity中跨我的网站转义(以及更多)HTML变量和参数。我尝试过使用默认的转义工具(EscapeHtmlReference、EscapeSqlReference等),但它们并不适合我的所有需要

因此,我基于org创建了自己的EventHandler。阿帕奇。速度应用程序。事件使生效EscapeSqlReference,但每次我尝试调用它时,都会出现一个转换错误

我创建的新类:

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";
}

}

我的速度。属性文件

eventhandler.referenceinsertion.class = gov.location.of.class.security.vtool.EscapeXmlPlusReference
eventhandler.escape.xmlplus.match = /params.*/

但是每次我加载一个页面,我都会得到一个强制转换异常

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

有什么我遗漏的小东西吗


共 (0) 个答案