【问题标题】:Correct syntax to convert struts1 logic tag to Struts2 if tag将 struts1 逻辑标记转换为 Struts2 if 标记的正确语法
【发布时间】:2016-10-16 14:52:38
【问题描述】:

我正在将 struts 迁移到 struts2 应用程序,但我不确定我的语法是否正确。我使用了这个 struts1 逻辑标签:

<logic:equal name="myForm" property="fromWhere"
    scope="request" value="search">
<app:pageBanner/>

我已将其转换为 Struts2,如下所示:

<s:if test="%{myForm.fromWhere == \"search\"}">

我的疑问是在 if 标记中使用 name="myForm" 和 property="fromWhere"。

当您搜索将 Struts1 迁移到 Struts2、Struts2 标签等时,我已经查看了 Google 中出现的大多数网站,如果有人知道提供有关如何使用此标签的更多详细信息的网站,包括示例或帮助从 struts1 迁移到 struts2,请将它们一起发布。我会很感激的。

感谢您抽出时间回复。

【问题讨论】:

    标签: jsp struts2 struts jsp-tags ognl


    【解决方案1】:

    s:if 标签内,您不应该使用the name="myForm" along with the property="fromWhere"。正确的语法

    <s:if test="myForm.fromWhere == 'search'">
    

    myForm 应该是具有公共 getter getMyForm() 的操作类变量,以便从视图访问此变量并评估 test 属性中的 OGNL 表达式。

    您可以找到here 的示例。

    【讨论】:

    • 罗曼,感谢您的回答。在您正确的 sytanx 示例中,您正在使用 myForm 以及与您的建议相矛盾的属性。是不是打错字了?
    • 不,我实际上没有得到什么矛盾?
    • 您在 s:if 标签内说过不要将 name="myForm" 与属性一起使用。你说正确的语法是: 但你在 if 标记内使用 myForm 。这就是我的意思,它是矛盾的。您的示例与我上面使用的非常相似。
    • 没错s:if标签既没有name属性也没有property属性。
    • 这说明了我在做什么。再次感谢您抽出宝贵时间回答并感谢您提供的示例。
    猜你喜欢
    • 1970-01-01
    • 2011-10-10
    • 1970-01-01
    • 2016-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-23
    • 1970-01-01
    相关资源
    最近更新 更多