@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); String title = "Test Servlet with Utilities"; out.println( ServletUtilities.headWithTitle(title) + "<body bgcolor=\"#fdf5e6\">\n" + "<h1>" + title + "</h1>\n" + "<p>Simple servlet for testing.</p>\n" + "</body></html>"); }
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); String title = "Reading All Request Parameters"; out.println( ServletUtilities.headWithTitle(title) + "<BODY BGCOLOR=\"#FDF5E6\">\n" + "<H1 ALIGN=CENTER>" + title + "</H1>\n" + "<TABLE BORDER=1 ALIGN=CENTER>\n" + "<TR BGCOLOR=\"#FFAD00\">\n" + "<TH>Parameter Name<TH>Parameter Value(s)"); Enumeration paramNames = request.getParameterNames(); while (paramNames.hasMoreElements()) { String paramName = (String) paramNames.nextElement(); out.println("<TR><TD>" + paramName + "\n<TD>"); String[] paramValues = request.getParameterValues(paramName); if (paramValues.length == 1) { String paramValue = paramValues[0]; if (paramValue.length() == 0) out.print("<I>No Value</I>"); else out.print(paramValue); } else { out.println("<UL>"); for (int i = 0; i < paramValues.length; i++) { out.println("<LI>" + paramValues[i]); } out.println("</UL>"); } } out.println("</TABLE>\n</BODY></HTML>"); }
public static String getLanguageCode(HttpServletRequest request) { String context = ServletUtilities.getContext(request); // worst case scenario default to English String langCode = "en"; // try to detect a default if defined if (CommonConfiguration.getProperty("defaultLanguage", context) != null) { langCode = CommonConfiguration.getProperty("defaultLanguage", context); } ArrayList<String> supportedLanguages = new ArrayList<String>(); if (CommonConfiguration.getSequentialPropertyValues("language", context) != null) { supportedLanguages = CommonConfiguration.getSequentialPropertyValues("language", context); } // if specified directly, always accept the override if (request.getParameter("langCode") != null) { if (supportedLanguages.contains(request.getParameter("langCode"))) { return request.getParameter("langCode"); } } // the request cookie is the next thing we check. this should be the primary means of figuring // langCode out Cookie[] cookies = request.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { if ("wildbookLangCode".equals(cookie.getName())) { if (supportedLanguages.contains(cookie.getValue())) { return cookie.getValue(); } } } } // finally, we will check the URL vs values defined in context.properties to see if we can set // the right context // TBD - future - detect browser supported language codes and locale from the HTTPServletRequest // object return langCode; }