Freemarker Servlet 和 Struts:访问模板中的 java 方法和变量

发布于 2024-12-24 18:45:51 字数 487 浏览 2 评论 0原文

我想访问 Struts Web 应用程序的会话、应用程序和请求变量。 它告诉我 Session 的类型是“HttpSessionHashModel”,并且查找 API 我看到这个类有一个方法“isEmpty()”。所以我尝试了例如

<#assign a = Session.isEmpty()>

,但它告诉我不存在这样的元素“Session.isEmpty”。

有谁知道为什么它不起作用?

在会话中,我可以通过以下方式访问几个类 <#assign b = Session["classname"]> (它告诉我 b 的类型为 freemarker.ext.beans.StringModel),但我既无法调用类 StringModel 的方法,也无法访问存储在“classname”中的对象和方法。

希望有人能帮忙

I want to access the Session, Application and Request variables of a Struts web application.
It tells me Session is of type 'HttpSessionHashModel', and looking up the API I saw this class has a method 'isEmpty()'. so I tried for example

<#assign a = Session.isEmpty()>

but it tells me there is no such element 'Session.isEmpty'.

does anyone have an Idea why it is not working?

In Session there are several classes which I could access via
<#assign b = Session["classname"]> (it tells me b is then of type freemarker.ext.beans.StringModel), but I can neither call the methods of class StringModel nor can I get to the objects and methods stored in 'classname'.

hope someone can help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

世界如花海般美丽 2024-12-31 18:45:51

使用 @s 宏:

随 Struts 分发的标签会自动可供 FreeMarker 模板使用。要使用任何标签,请添加“@s”。在标签名称前面。喜欢:

<@s.if test="printName">
  <@s.property value="myBeanProperty" />
</@s.if>

参考

Use the @s macro:

Tags distributed with Struts are automatically made available to FreeMarker templates. To use any tag add "@s." in front of the tag name. Like:

<@s.if test="printName">
  <@s.property value="myBeanProperty" />
</@s.if>

References

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