Take the Locale into Consideration in the Application Controller
You’ve already seen
LocaleSupport used in a JSP custom tag, but what
about a business component such as a servlet? Its use in this
scenario might be appropriate if you’re designing an
application controller to route users to locale-specific JSP pages.
As with the LocaleSupport interface, this is not
meant to be an exhaustive component, but a starting point for your
own development.
The essence of how this business component can use
LocaleSupport is as follows:
Look for the user’s preferred locale attribute from the name defined in the
LocaleSupportinterface.If the user’s preferred locale is not set, fall back to the application’s default locale defined in the
LocaleSupportinterface.Identify the requested page and form an appropriate page name by tacking on the preferred locale to the page and adding the appropriate extension.
Forward the user to the proper locale-s
pecific JSP page.
Example 8-12 shows one such application controller.
package com.ora.i18n.servlets; import com.ora.i18n.LocaleSupport; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.*; import java.io.IOException; import java.util.Locale; public class LocalePageServlet extends HttpServlet { private final static String DEFAULT_PAGE = "index"; private final static String PAGE_ID_PARAMETER = "pageID"; private final static String ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access