Moo*_*oon 1 java struts2 internationalization
我正在阅读以下网址上的struts2教程.
http://struts.apache.org/2.2.1/docs/message-resource-files.html
它解释了如何读取视图文件中属性键的值,但它没有解释如何读取操作类或模型类中的属性值.
如何在动作或模型类中读取属性键的值?
使用该方法ActionSupport.getText(String)
.例如 :
messages.properties
foo.bar=foobar
Run Code Online (Sandbox Code Playgroud)
在struts.xml
<constant name="struts.custom.i18n.resources" value="messages" />
Run Code Online (Sandbox Code Playgroud)
动作类
public class TestAction extends ActionSupport {
public void method() {
getText("foo.bar");
}
}
Run Code Online (Sandbox Code Playgroud)
@Moon:如果我没有扩展ActionSupport怎么办?
对于未扩展的类ActionSupport
,请使用以下(在Struts2的运行时):
ActionSupport actionSupport = new ActionSupport();
actionSupport.getText("foo.bar");
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4845 次 |
最近记录: |