【问题标题】:Using getText() for the getting property in Struts 2在 Struts 2 中使用 getText() 获取属性
【发布时间】:2014-04-12 14:57:21
【问题描述】:

我正在使用 JSP 开发 Struts2 框架。

在我的samplePrj.properties 文件中,在那个

com.samplePrj.Successmessage = Saved Successful

是一个属性。我需要在我的 JSP 页面中使用这个值,使用 Struts2。

那么如何在我的 JSP 页面中获取 "com.samplePrj.Successmessage" 的值。

【问题讨论】:

    标签: java javascript jsp struts2 resourcebundle


    【解决方案1】:

    使用text 标签

    <s:i18n name="samplePrj">
        <s:text name="com.samplePrj.Successmessage" />
    </s:i18n>
    

    它将使用samplePrj.properties 中的i18n 标签加载捆绑包,并在其中打印来自键com.samplePrj.Successmessage 的值。

    或者您可以将它与getText() 一起使用,但您的操作类应该扩展ActionSupport

    <s:property value="getText('com.samplePrj.Successmessage')"/>
    

    【讨论】:

    • 先生,我想检查一个带有 .property 文件值的变量值。我们该怎么做??即使用 if 条件(a == 属性文件值)
    • 如果变量在值堆栈中,那么您可以在if 标签的test 属性中的OGNL 表达式中使用它。喜欢&lt;s:if test="myVariable == getText('com.samplePrj.Successmessage')"&gt;
    【解决方案2】:

    您可以使用 getText() 方法从属性文件中读取。

    <s:set var="variable" value="getText('com.samplePrj.Successmessage')"/>
    <s:if test="myVariable == #variable"> 
      //do what u want
    </s:if>
    

    【讨论】:

      猜你喜欢
      • 2015-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-29
      • 1970-01-01
      • 2016-08-19
      相关资源
      最近更新 更多