FileDocCategorySizeDatePackage
AppletLocaleServlet.javaAPI DocExample3957Wed Jan 17 20:18:32 GMT 2001None

AppletLocaleServlet

public class AppletLocaleServlet extends HttpServlet

Fields Summary
Constructors Summary
Methods Summary
public voiddoGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)


    String appletName = request.getParameter("Applet");
    String bundleName = request.getParameter("Bundle");
    String acceptLanguage = request.getHeader("Accept-Language");
    String acceptCharset = request.getHeader("Accept-Charset");

    LocaleNegotiator negotiator =
      new LocaleNegotiator(bundleName, acceptLanguage, acceptCharset);

    Locale locale = negotiator.getLocale();
    String charset = negotiator.getCharset();
    ResourceBundle bundle = negotiator.getBundle();

    response.setContentType("text/plain; charset=" + charset);
    response.setHeader("Content-Language", locale.getLanguage());

PrintWriter out = response.getWriter();
    out.println("<HTML>");
    out.println();
    out.println("<HEAD>");
    out.println("  <TITLE>AppletLocale servlets</TITLE>");
    out.println();
    out.println("<BODY>");
    out.println();
    out.println("<APPLET CODE=\"" + appletName + "\" WIDTH=\""
                  + bundle.getString("Width")
                  + "\" HEIGHT=\"" + bundle.getString("Width")
                  + "\"> ");
    out.println("<PARAM NAME=\"language\" VALUE=\"" + locale.getLanguage() + "\">");
    out.println("<PARAM NAME=\"country\" VALUE=\"" + locale.getCountry() + "\">");
    out.println("<PARAM NAME=\"variant\" VALUE=\"" + locale.getVariant() + "\">");
    Enumeration parameters = bundle.getKeys();
    String key;
    while (parameters.hasMoreElements()) {
      key = (String)parameters.nextElement();
      out.println("<PARAM NAME=\"" + key + "\" VALUE=\""
                    + bundle.getString(key) + "\">");
    }
    out.println("</APPLET>");
    out.println();
    out.println("</BODY>");
    out.println();
    out.println("</HTML>");