Java 在 Struts 2 中使用 getText() 获取属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23031984/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using getText() for the getting property in Struts 2
提问by hKs
I am working on the Struts2 framework with JSP.
我正在使用 JSP 开发 Struts2 框架。
In my samplePrj.properties
file, in that
在我的samplePrj.properties
文件中,在那个
com.samplePrj.Successmessage = Saved Successful
is an attribute. I need to use this value in my JSP page, using Struts2.
是一个属性。我需要在我的 JSP 页面中使用这个值,使用 Struts2。
so how can I get the value of "com.samplePrj.Successmessage"
in my JSP page.
那么如何"com.samplePrj.Successmessage"
在我的 JSP 页面中获取 的值。
采纳答案by Roman C
Use the text
tag
使用text
标签
<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.
它将使用i18n
tag from加载包samplePrj.properties
并从其中的键打印值com.samplePrj.Successmessage
。
or you can use it with getText()
but your action class should extend ActionSupport
.
或者你可以使用它,getText()
但你的动作类应该扩展ActionSupport
.
<s:property value="getText('com.samplePrj.Successmessage')"/>
回答by Roman C
You can use getText() method to read from properties files.
您可以使用 getText() 方法从属性文件中读取。
<s:set var="variable" value="getText('com.samplePrj.Successmessage')"/>
<s:if test="myVariable == #variable">
//do what u want
</s:if>