| <bean:message>顯示訊息資源檔中對應於key的value,例如: <bean:message key="welcome.title"/>
<bean:message key="welcome.greeting" arg1="caterpillar" arg2="good morning"/> 來看一個使用的例子,例如在 使用 LookupDispatchAction 中,可以將表單網頁改為JSP,並且利用<bean:message>來寫出按鈕的顯示值:
<%@ taglib uri="/tags/struts-bean" prefix="bean" %> 如果訊息檔案中是中文資料,則會傳回以下的內容: <html>
<head> <title>Edit</title> </head> <body> <form name='editForm' method='post' action='/strutsapp/edit.do'> <input type='submit' name='method' value='存檔'/> <input type='submit' name='method' value='預覽'/> <input type='submit' name='method' value='重設'/> </form> </body> </html> 如此一來,JSP網頁會與訊息檔案內容同步,就不用分開管理網頁訊息及訊息檔案內容了。 <bean:message>中還可以設定參數,例如: <bean:message key="welcome.greeting"
arg1="caterpillar" arg2="good morning"/> arg1、arg2等可以替代訊息檔中{0}、{1}等位置的訊息,最多可以有五個。 |
|