struts.xml
<struts>
<constant name="struts.custom.i18n.resources" value="global" />
<constant name="struts.devmode" value="true" />
<package name="default" namespace="/" extends="struts-default">
<action name="locale" class="com.h3.common.action.localeaction">
<result name="success">pages/welcome.jsp</result>
<param name="englishparam">english</param>
<param name="chineseparam">chinese</param>
<param name="franceparam">france</param>
</action>
</package>
</struts>
要从struts.xml中获取静态参数值,action类必须实现参数化parameterizable接口。动作的静态参数是由staticparams拦截,其中包括在默认堆栈控制
//...
import com.opensymphony.xwork2.config.entities.parameterizable;
public class localeaction implements parameterizable{
map<string, string> params;
//...
public void setparams(map<string, string> params) {
this.params = params;
}
}
在动作类的初始化,如果创建了getter和setter方法得当,staticparams拦截器将设置预先定义的参数值,以对应于该“参数”的每javabean属性。
//...
import com.opensymphony.xwork2.config.entities.parameterizable;
public class localeaction implements parameterizable{
string englishparam;
string chineseparam;
string franceparam;
public string getenglishparam() {
return englishparam;
}
public void setenglishparam(string englishparam) {
this.englishparam = englishparam;
}
public string getchineseparam() {
return chineseparam;
}
public void setchineseparam(string chineseparam) {
this.chineseparam = chineseparam;
}
public string getfranceparam() {
return franceparam;
}
public void setfranceparam(string franceparam) {
this.franceparam = franceparam;
}
//...
}
在浏览器中打开url:http://localhost:8080/configure-param/locale.action
