1
我正在閱讀以下url的struts2教程。如何讀取類中的全局屬性文件?
http://struts.apache.org/2.2.1/docs/message-resource-files.html
它說明了如何讀取一個視圖文件的屬性鍵的值,但它並沒有解釋如何在動作類或者一個模型類讀取屬性值。
如何讀取動作或模型類中的屬性值的值?
我正在閱讀以下url的struts2教程。如何讀取類中的全局屬性文件?
http://struts.apache.org/2.2.1/docs/message-resource-files.html
它說明了如何讀取一個視圖文件的屬性鍵的值,但它並沒有解釋如何在動作類或者一個模型類讀取屬性值。
如何讀取動作或模型類中的屬性值的值?
使用方法ActionSupport.getText(String)
。例如:
messages.properties
foo.bar=foobar
struts.xml的
<constant name="struts.custom.i18n.resources" value="messages" />
Action類
public class TestAction extends ActionSupport {
public void method() {
getText("foo.bar");
}
}
@Moon:如果我不擴展ActionSupport?
對於類不延長ActionSupport
,(在Struts2的的運行時間)使用以下命令:
ActionSupport actionSupport = new ActionSupport();
actionSupport.getText("foo.bar");
//如果我不延長什麼ActionSupport的? – Moon
如果您有充分的理由不擴展'ActionSupport',那麼就看一下'ActionSupport'並且實現它爲'getText'做的事情。它來自'TextProvider'界面。否則,請擴展'ActionSupport'。 –