Time for action – externalizing messages

Let's see how to externalize the label texts in our addProduct.jsp file:

  1. We open our addProduct.jsp file and add the following taglib reference at the top:
    <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
  2. 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>
  3. 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
  4. Now, we open our web application context configuration file DispatcherServlet-context.xml ...

Get Spring MVC Beginner’s Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.