是“应用程序” EscapeTool 中的保留字?

发布于 2024-12-26 19:49:35 字数 1067 浏览 2 评论 0原文

最近,我在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回心转意 2025-01-02 19:49:35

EscapeTool 不会在上下文中放置任何内容,因此它不会覆盖您的 $application 变量。要找出覆盖任何变量的内容,您可以尝试

$application.class.name

当模板中使用 $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

$application.class.name

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文