Mega Code Archive

 
Categories / Java / JSP
 

Internationalized Web Applications

/* 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);   } }