Let's see how to externalize the label texts in our addProduct.jsp
file:
We open our
addProduct.jsp
file and add the followingtaglib
reference at the top:<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
Change the product ID
<label>
tag's value as<spring:message code="addProdcut.form.productId.label"/>
, as shown as follows:<label class="control-label col-lg-2 col-lg-2" for="productId"> <spring:message code= "addProduct.form.productId.label"/> </label>
We create a file called
messages.properties
under/src/main/resources
in our project and add the following line in it:addProduct.form.productId.label = New Product ID
Now, we open our web application context configuration file
DispatcherServlet-context.xml
fromsrc/main/webapp/WEB-INF/spring/webcontext/
and add the following bean definition in it:<bean id= "messageSource" class="org.springframework.context.support.ResourceBundleMessageSource...