<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" %>如果讯息档案中是中文数据,则会传回以下的内容:
<%@page contentType="text/html; charset=Big5"%>
<html>
<head>
<title>Edit</title>
</head>
<body>
<form name='editForm' method='post'
action='/strutsapp/edit.do'>
<input type='submit' name='method'
value='<bean:message key="button.save"/>'/>
<input type='submit' name='method'
value='<bean:message key="button.preview"/>'/>
<input type='submit' name='method'
value='<bean:message key="button.reset"/>'/>
</form>
</body>
</html>
<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 key="welcome.greeting" arg1="caterpillar" arg2="good morning"/>
arg1、arg2等可以替代讯息文件中{0}、{1}等位置的讯息,最多可以有五个。