O'Reilly logo

JavaServer Pages, Second Edition by Hans Bergsten

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Generating Localized Output

Now that you have an understanding of the type of internationalization support Java provides, let’s look at a concrete example. However, instead of using the internationalization classes directly in the pages, we’ll use the JSTL I18N actions based on these classes.

The example application, briefly described in the introduction to this chapter, lets visitors voice their opinion by selecting one of the answers to a question, as well as seeing how others have answered. The text, numbers, and dates are available in three different languages. Figure 13-1 shows all the pages used in this application and how they are related.

Localized poll application pages

Figure 13-1. Localized poll application pages

The first page the user sees is the poll.jsp page, shown in Figure 13-2. The language that displays the contents the first time this page is requested is based on the Accept-Language request header value. The top part of the page contains radio buttons for the three supported languages and a Submit button. If the user wants the application to be presented in another language, he selects the corresponding radio button and clicks Submit, causing the page to be requested again, this time with a language parameter included in the request. The value of the language parameter is then used to select the corresponding locale and display the page in the selected locale’s language. Information about the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required