Struts框架中的國際化

在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>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章