Using getText() for the getting property in Struts 2

白昼怎懂夜的黑 提交于 2021-01-18 04:41:07

问题


I am working on the Struts2 framework with JSP.

In my samplePrj.properties file, in that

com.samplePrj.Successmessage = Saved Successful

is an attribute. I need to use this value in my JSP page, using Struts2.

so how can I get the value of "com.samplePrj.Successmessage" in my JSP page.


回答1:


Use the text tag

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

it will load the bundle using i18n tag from samplePrj.properties and print the value from key com.samplePrj.Successmessage in it.

or you can use it with getText() but your action class should extend ActionSupport.

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



回答2:


You can use getText() method to read from properties files.

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


来源:https://stackoverflow.com/questions/23031984/using-gettext-for-the-getting-property-in-struts-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!