<bean:message> is used to display a localized and possibly parameterised message from a property file bundled with application.

Common Setup

Resource files should be names according to locale and country, like:

Struts Taglib

struts-config.xml:

<message-resources parameter="com.acme.webboard.Messages"/>

JSP file:

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>

<%-- No arguments --%>
<bean:message key="webboard.greeting"/>

<%-- Passing arguments to a message in a JSP2.0 container --%>
<bean:message key="webboard.greeting" arg0="${user.name}"/>

JSTL

web.xml:

<context-param>
  <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
  <param-value>com.acme.webboard.Messages</param-value>
</context-param>

JSP file:

<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>

<%-- No arguments --%>
<fmt:message key="webboard.greeting"/>

<%-- Passing arguments to a message --%>
<fmt:message key="webboard.greeting"/>
  <fmt:param value="${user.name}"/>
</fmt:message>

More information:

JSTLTagsBeanMessage (last edited 2009-09-20 23:11:56 by localhost)