Dynamic language in spring MVC example

Thursday, July 28th, 2016 (0 Comment)

In this article, we make a simple example about change dynamic language in spring mvc. We will switch between french and english.

We will have two option for dynamic language in spring mvc:

  1. Use default LocaleResolver in spring framework
  2. Customize LocaleResolver with your purpose

1) Create project’s structure for dynamic language in spring mvc

with pom.xml to config maven

2) Properties file to store languages

messages_en.properties

messages_fr.properties

3) Config servlet and web file

web.xml

servlet-context.xml

  • Line 42 – 44: if use handle change dynamic language in spring then open these lines and use class I18nLocaleResolver.java

4) Object UserInfo and Controller

UserInfo.java

HelloWorldController.java

  • Line 14 – 15: if you use these lines, you open line 42 – 44 in servlet-context.xml file to handle language in I18nLocaleResolver.java

5) Jsp pages for interface

index.jsp

hello.jsp

All above use default LocaleResolver to change dynamic language in spring mvc.

Besides, you can handle change dynamic language in spring by your purpose as loading and storing language in database or xml file, you need to create class I18nLocaleResolver extends SessionLocaleResolver and customize and open line 42 – 44 in servlet-context.xml and open line 14 – 15 in HelloWorldController.java.

I18nLocaleResolver.java

You can run success dynamic language in spring mvc with jboss 7.1 server.

Tags: , , ,

Related Posts

spring
How to create quartz spring dynamic in database
spring
Spring mvc mongodb crud users roles
spring
Java spring mvc tutorial on lvtutorial.com
spring
Angularjs spring mvc crud example

Related Posts

spring
How to create quartz spring dynamic in database
spring
Spring mvc mongodb crud users roles
spring
Java spring mvc tutorial on lvtutorial.com
spring
Angularjs spring mvc crud example

Leave a Reply

Your email address will not be published. Required fields are marked *