是“应用程序” EscapeTool 中的保留字?
最近,我在spring框架中使用apachevelocity作为视图模板,为了转义HTML实体,我引入了“org.apache.velocity.tools.generic.EscapeTool”,但是,然后我发现了名为“$”的变量application”现在无法工作,任何以“$application”命名的变量都显示为空白,例如“$!application.name”。
当我删除速度工具配置时,可以正确读取“$application”。那么有人知道“$application”是速度转义工具中的保留字还是我在配置时犯了错误?
工具箱配置:
<toolbox>
<tool>
<key>esc</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.EscapeTool</class>
</tool>
</toolbox>
spring-beans XML 中的配置:
<bean id="viewResolver"
class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
<property name="cache" value="true" />
<property name="exposeSpringMacroHelpers" value="true" />
<property name="toolboxConfigLocation" value="/WEB-INF/toolbox.xml" />
</bean>
在模板文件中:
<div class="description">
<h2>Application Name:$!application.name</h2>
</div>
提前致谢!
Recently, I use apache velocity for view template in spring framework, and in order to escape the HTML entity, I introduced the "org.apache.velocity.tools.generic.EscapeTool", however, then I found the variable named with "$application" cannot work now, that any variable named with "$application" shows blank, e.g. "$!application.name".
When I removed the velocity tool configuration, "$application" can be read correctly. So anyone knows if the "$application" a reserved word in velocity escape tool or I make a mistake when configuration?
Toolbox config:
<toolbox>
<tool>
<key>esc</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.EscapeTool</class>
</tool>
</toolbox>
Config in spring-beans XML:
<bean id="viewResolver"
class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
<property name="cache" value="true" />
<property name="exposeSpringMacroHelpers" value="true" />
<property name="toolboxConfigLocation" value="/WEB-INF/toolbox.xml" />
</bean>
In template file:
<div class="description">
<h2>Application Name:$!application.name</h2>
</div>
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
EscapeTool 不会在上下文中放置任何内容,因此它不会覆盖您的 $application 变量。要找出覆盖任何变量的内容,您可以尝试
当模板中使用 $application 时,VelocityTools 会自动返回 servletContext,但是(在 Tools 2.0 的情况下)您可以配置是否要首选用户设置的变量(默认)或 servlet api 对象。我不记得是否可以在工具 1.4 中进行配置,但我确信您可以查找它。
无论如何,在 Tools 2.x 中,它不是保留的,但它也带有默认值。由于它的作用与保留的一样,我猜您要么关闭了 userOverwrite,要么正在使用 Tools 1.4。
The EscapeTool does not put anything in the context, so it is not overriding your $application variable. To find out what is overriding any variable, you might try
VelocityTools does automatically return the servletContext when $application is used in a template, but (in the case of Tools 2.0) you can configure whether you want to prefer user-set variables (the default) or the servlet api objects. I don't offhand recall if that can be configured in Tools 1.4, but i'm sure you can look it up.
In any case, in Tools 2.x, it is not reserved, but it is also does come with a default value. Since it is acting as those it's reserved, i'm guessing you either turned off userOverwrite or else are using Tools 1.4.