Internationalized Web Applications: JavaServer Pages : I18N « JSP « Java






Internationalized Web Applications: JavaServer Pages

/*
Java Internationalization
By Andy Deitsch, David Czarnecki

ISBN: 0-596-00019-7
O'Reilly
*/

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class JSPLocaleNegotiatorServlet extends HttpServlet {

  private static final String defaultJSP = "/jsp/default_en_US.jsp";
  private static final String jspExtension = ".jsp";

  public void doGet(HttpServletRequest request, HttpServletResponse response) throws
      IOException, ServletException {

    Locale usersLocale = request.getLocale();

    StringBuffer jspWithLocale = new StringBuffer();
    if (request.getParameter("jsppage") != null) {
      jspWithLocale.append(request.getParameter("jsppage"));
      jspWithLocale.append("_");
      jspWithLocale.append(usersLocale.toString());
      jspWithLocale.append(jspExtension);
    } else
      jspWithLocale.append(defaultJSP);

    response.setLocale(usersLocale);
    getServletConfig().getServletContext()
        .getRequestDispatcher(jspWithLocale.toString())
        .forward(request,response);
  }
}


           
       








Related examples in the same category

1.Locale info
2.Locale Display in a JSP
3.Current Locale
4.JSP: Define the string in tag (I18N)
5.JSP Internationalization and Localized Content 1JSP Internationalization and Localized Content 1
6.JSP Internationalization and Localized Content 2JSP Internationalization and Localized Content 2
7.JSP Internationalization and Localized Content:Currency Formatting and locales
8.JSP Internationalization and Localized Content: Date Formatting and locale