JSP: Exemple d’une application web internationnalisée

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


           
              

A Voir sur le même Sujet:

  • EXEMPLE D APPLICATION WEB JAVA
  • exemples.de.code.en.java

Leave a Reply

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