2011-09-21 38 views

回答

6

使用方法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"); 
+0

//如果我不延長什麼ActionSupport的? – Moon

+2

如果您有充分的理由不擴展'ActionSupport',那麼就看一下'ActionSupport'並且實現它爲'getText'做的事情。它來自'TextProvider'界面。否則,請擴展'ActionSupport'。 –