在Struts中可以通过配置资源文件,能使得我们的软件同时支持多种语言。
在struts-config.xml中,<message-resources parameter="com.student.struts.ApplicationResources" />
红字标示的就是资源文件的路径
资源文件是以‘.properties’结尾的
资源文件中是一些key-value对
ApplicationResources.properties(英文)
ApplicationResources_zh.properties(原文)
页面配合Struts标签库标签
<bean:message key=“资源文件中的key”/>
DispatchAction
通常,在一个Action类中只能完成一种业务操作,如果希望在同一个Action类中完成一组相关的业务操作,可以使用DispatchAction类。
配置DispatchAction
<action
path="/…"
type=“…"
name=“…"
parameter="method"
/>
提交请求:“***.do?method=Method1”
红字表示该请求提交给DispatchAction中的Method1来进行处理
注:Method1方法的参数和Action类中的execute方法的一致。
LookDispatchAction
该类是DispatchAction的子类,主要处理一张表单两个提交按钮的问题。
<action
name=“……"
path="/…"
type=“……"
parameter="action”
/>
两个提交按钮
<html:submit property="action"><bean:message key="label.submit"/></html:submit>
<html:submit property="action"><bean:message key="label.confirm"/></html:submit>
LookDispatchAction类
public ActionForward checkUser(…)
public ActionForward saveUser(…)
protected Map getKeyMethodMap() {
Map map = new HashMap();
map.put("label.confirm", "checkUser");
map.put("label.submit", "saveUser");
return map;
}
<jsp:forward page="/user/login.jsp"></jsp:forward>