Building multilingual pages

Next we will learn how to create a multilingual page (in English and French) using only one JSP, and display it in English by default, with a link to switch to French. We will then store the text outside the JSP, in both languages, in separate .properties files.

How to do it…

Here are the steps to build a bilingual JSP view:

  1. Create the JSP:
    <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
    
    <html>
    <body>
      <h1><spring:message code="home.title" /></h1>
      <p><spring:message code="home.intro" /></p>
    
      <p>
        <a href="?lang=en">English</a> |
        <a href="?lang=fr">French</a>
      </p>
    </body>
    </html>
  2. Create the English .properties file src/main/resources/messages.properties:
    home.title=Home home.intro=This is a magnificent ...

Get Spring Cookbook 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.