[tomcat] branch 9.0.x updated: Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=64000 i18n use client

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[tomcat] branch 9.0.x updated: Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=64000 i18n use client

markt
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/9.0.x by this push:
     new 5b9a3b4  Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=64000 i18n use client
5b9a3b4 is described below

commit 5b9a3b4a5b0818723ba0fc553dda4c6024849c92
Author: Mark Thomas <[hidden email]>
AuthorDate: Tue Jan 14 19:45:03 2020 +0000

    Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=64000 i18n use client
   
    Ensure that the example web application uses the client locale rather
    than the server locale where it provides i18n support
---
 webapps/docs/changelog.xml                         |  9 +++++++++
 .../examples/WEB-INF/classes/CookieExample.java    | 21 ++++++++++-----------
 .../WEB-INF/classes/RequestHeaderExample.java      |  6 +++---
 .../WEB-INF/classes/RequestInfoExample.java        | 16 ++++++++--------
 .../WEB-INF/classes/RequestParamExample.java       | 18 +++++++++---------
 .../examples/WEB-INF/classes/SessionExample.java   | 22 +++++++++++-----------
 6 files changed, 50 insertions(+), 42 deletions(-)

diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index dacf6f5..7006a2f 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -157,6 +157,15 @@
       </fix>
     </changelog>
   </subsection>
+  <subsection name="Web applications">
+    <changelog>
+      <fix>
+        <bug>64000</bug>: In the examples web application, where a Servlet
+        example includes ii18n support, the Locale used should be based on the
+        request locale and not the server locale. (markt)
+      </fix>
+    </changelog>
+  </subsection>
   <subsection name="Other">
     <changelog>
       <fix>
diff --git a/webapps/examples/WEB-INF/classes/CookieExample.java b/webapps/examples/WEB-INF/classes/CookieExample.java
index c62463b..3774e05 100644
--- a/webapps/examples/WEB-INF/classes/CookieExample.java
+++ b/webapps/examples/WEB-INF/classes/CookieExample.java
@@ -39,13 +39,12 @@ public class CookieExample extends HttpServlet {
 
     private static final long serialVersionUID = 1L;
 
-    private static final ResourceBundle RB = ResourceBundle.getBundle("LocalStrings");
-
     @Override
     public void doGet(HttpServletRequest request,
                       HttpServletResponse response)
         throws IOException, ServletException
     {
+        ResourceBundle rb = ResourceBundle.getBundle("LocalStrings",request.getLocale());
 
         String cookieName = request.getParameter("cookiename");
         String cookieValue = request.getParameter("cookievalue");
@@ -64,7 +63,7 @@ public class CookieExample extends HttpServlet {
         out.println("<head>");
         out.println("<meta charset=\"UTF-8\" />");
 
-        String title = RB.getString("cookies.title");
+        String title = rb.getString("cookies.title");
         out.println("<title>" + title + "</title>");
         out.println("</head>");
         out.println("<body bgcolor=\"white\">");
@@ -91,7 +90,7 @@ public class CookieExample extends HttpServlet {
             if (session != null) {
                 sessionId = session.getId();
             }
-            out.println(RB.getString("cookies.cookies") + "<br>");
+            out.println(rb.getString("cookies.cookies") + "<br>");
             for (int i = 0; i < cookies.length; i++) {
                 Cookie cookie = cookies[i];
                 String cName = cookie.getName();
@@ -102,25 +101,25 @@ public class CookieExample extends HttpServlet {
                             + "<br><br>");
             }
         } else {
-            out.println(RB.getString("cookies.no-cookies"));
+            out.println(rb.getString("cookies.no-cookies"));
         }
 
         if (aCookie != null) {
             out.println("<P>");
-            out.println(RB.getString("cookies.set") + "<br>");
-            out.print(RB.getString("cookies.name") + "  "
+            out.println(rb.getString("cookies.set") + "<br>");
+            out.print(rb.getString("cookies.name") + "  "
                       + HTMLFilter.filter(cookieName) + "<br>");
-            out.print(RB.getString("cookies.value") + "  "
+            out.print(rb.getString("cookies.value") + "  "
                       + HTMLFilter.filter(cookieValue));
         }
 
         out.println("<P>");
-        out.println(RB.getString("cookies.make-cookie") + "<br>");
+        out.println(rb.getString("cookies.make-cookie") + "<br>");
         out.print("<form action=\"");
         out.println("CookieExample\" method=POST>");
-        out.print(RB.getString("cookies.name") + "  ");
+        out.print(rb.getString("cookies.name") + "  ");
         out.println("<input type=text length=20 name=cookiename><br>");
-        out.print(RB.getString("cookies.value") + "  ");
+        out.print(rb.getString("cookies.value") + "  ");
         out.println("<input type=text length=20 name=cookievalue><br>");
         out.println("<input type=submit></form>");
 
diff --git a/webapps/examples/WEB-INF/classes/RequestHeaderExample.java b/webapps/examples/WEB-INF/classes/RequestHeaderExample.java
index 79e7bac..6d8a442 100644
--- a/webapps/examples/WEB-INF/classes/RequestHeaderExample.java
+++ b/webapps/examples/WEB-INF/classes/RequestHeaderExample.java
@@ -40,13 +40,13 @@ public class RequestHeaderExample extends HttpServlet {
 
     private static final long serialVersionUID = 1L;
 
-    private static final ResourceBundle RB = ResourceBundle.getBundle("LocalStrings");
-
     @Override
     public void doGet(HttpServletRequest request,
                       HttpServletResponse response)
         throws IOException, ServletException
     {
+        ResourceBundle rb = ResourceBundle.getBundle("LocalStrings",request.getLocale());
+
         response.setContentType("text/html");
         response.setCharacterEncoding("UTF-8");
 
@@ -55,7 +55,7 @@ public class RequestHeaderExample extends HttpServlet {
         out.println("<head>");
         out.println("<meta charset=\"UTF-8\" />");
 
-        String title = RB.getString("requestheader.title");
+        String title = rb.getString("requestheader.title");
         out.println("<title>" + title + "</title>");
         out.println("</head>");
         out.println("<body bgcolor=\"white\">");
diff --git a/webapps/examples/WEB-INF/classes/RequestInfoExample.java b/webapps/examples/WEB-INF/classes/RequestInfoExample.java
index 952e501..791e088 100644
--- a/webapps/examples/WEB-INF/classes/RequestInfoExample.java
+++ b/webapps/examples/WEB-INF/classes/RequestInfoExample.java
@@ -36,13 +36,13 @@ public class RequestInfoExample extends HttpServlet {
 
     private static final long serialVersionUID = 1L;
 
-    private static final ResourceBundle RB = ResourceBundle.getBundle("LocalStrings");
-
     @Override
     public void doGet(HttpServletRequest request,
                       HttpServletResponse response)
         throws IOException, ServletException
     {
+        ResourceBundle rb = ResourceBundle.getBundle("LocalStrings",request.getLocale());
+
         response.setContentType("text/html");
         response.setCharacterEncoding("UTF-8");
 
@@ -51,7 +51,7 @@ public class RequestInfoExample extends HttpServlet {
         out.println("<head>");
         out.println("<meta charset=\"UTF-8\" />");
 
-        String title = RB.getString("requestinfo.title");
+        String title = rb.getString("requestinfo.title");
         out.println("<title>" + title + "</title>");
         out.println("</head>");
         out.println("<body bgcolor=\"white\">");
@@ -72,23 +72,23 @@ public class RequestInfoExample extends HttpServlet {
 
         out.println("<h3>" + title + "</h3>");
         out.println("<table border=0><tr><td>");
-        out.println(RB.getString("requestinfo.label.method"));
+        out.println(rb.getString("requestinfo.label.method"));
         out.println("</td><td>");
         out.println(HTMLFilter.filter(request.getMethod()));
         out.println("</td></tr><tr><td>");
-        out.println(RB.getString("requestinfo.label.requesturi"));
+        out.println(rb.getString("requestinfo.label.requesturi"));
         out.println("</td><td>");
         out.println(HTMLFilter.filter(request.getRequestURI()));
         out.println("</td></tr><tr><td>");
-        out.println(RB.getString("requestinfo.label.protocol"));
+        out.println(rb.getString("requestinfo.label.protocol"));
         out.println("</td><td>");
         out.println(HTMLFilter.filter(request.getProtocol()));
         out.println("</td></tr><tr><td>");
-        out.println(RB.getString("requestinfo.label.pathinfo"));
+        out.println(rb.getString("requestinfo.label.pathinfo"));
         out.println("</td><td>");
         out.println(HTMLFilter.filter(request.getPathInfo()));
         out.println("</td></tr><tr><td>");
-        out.println(RB.getString("requestinfo.label.remoteaddr"));
+        out.println(rb.getString("requestinfo.label.remoteaddr"));
         out.println("</td><td>");
         out.println(HTMLFilter.filter(request.getRemoteAddr()));
         out.println("</td></tr>");
diff --git a/webapps/examples/WEB-INF/classes/RequestParamExample.java b/webapps/examples/WEB-INF/classes/RequestParamExample.java
index be07415..b5e2dfa 100644
--- a/webapps/examples/WEB-INF/classes/RequestParamExample.java
+++ b/webapps/examples/WEB-INF/classes/RequestParamExample.java
@@ -36,13 +36,13 @@ public class RequestParamExample extends HttpServlet {
 
     private static final long serialVersionUID = 1L;
 
-    private static final ResourceBundle RB = ResourceBundle.getBundle("LocalStrings");
-
     @Override
     public void doGet(HttpServletRequest request,
                       HttpServletResponse response)
         throws IOException, ServletException
     {
+        ResourceBundle rb = ResourceBundle.getBundle("LocalStrings",request.getLocale());
+
         response.setContentType("text/html");
         response.setCharacterEncoding("UTF-8");
 
@@ -51,7 +51,7 @@ public class RequestParamExample extends HttpServlet {
         out.println("<head>");
         out.println("<meta charset=\"UTF-8\" />");
 
-        String title = RB.getString("requestparams.title");
+        String title = rb.getString("requestparams.title");
         out.println("<title>" + title + "</title>");
         out.println("</head>");
         out.println("<body bgcolor=\"white\">");
@@ -74,23 +74,23 @@ public class RequestParamExample extends HttpServlet {
         out.println("<h3>" + title + "</h3>");
         String firstName = request.getParameter("firstname");
         String lastName = request.getParameter("lastname");
-        out.println(RB.getString("requestparams.params-in-req") + "<br>");
+        out.println(rb.getString("requestparams.params-in-req") + "<br>");
         if (firstName != null || lastName != null) {
-            out.println(RB.getString("requestparams.firstname"));
+            out.println(rb.getString("requestparams.firstname"));
             out.println(" = " + HTMLFilter.filter(firstName) + "<br>");
-            out.println(RB.getString("requestparams.lastname"));
+            out.println(rb.getString("requestparams.lastname"));
             out.println(" = " + HTMLFilter.filter(lastName));
         } else {
-            out.println(RB.getString("requestparams.no-params"));
+            out.println(rb.getString("requestparams.no-params"));
         }
         out.println("<P>");
         out.print("<form action=\"");
         out.print("RequestParamExample\" ");
         out.println("method=POST>");
-        out.println(RB.getString("requestparams.firstname"));
+        out.println(rb.getString("requestparams.firstname"));
         out.println("<input type=text size=20 name=firstname>");
         out.println("<br>");
-        out.println(RB.getString("requestparams.lastname"));
+        out.println(rb.getString("requestparams.lastname"));
         out.println("<input type=text size=20 name=lastname>");
         out.println("<br>");
         out.println("<input type=submit>");
diff --git a/webapps/examples/WEB-INF/classes/SessionExample.java b/webapps/examples/WEB-INF/classes/SessionExample.java
index 471b66b..a306560 100644
--- a/webapps/examples/WEB-INF/classes/SessionExample.java
+++ b/webapps/examples/WEB-INF/classes/SessionExample.java
@@ -39,13 +39,13 @@ public class SessionExample extends HttpServlet {
 
     private static final long serialVersionUID = 1L;
 
-    private static final ResourceBundle RB = ResourceBundle.getBundle("LocalStrings");
-
     @Override
     public void doGet(HttpServletRequest request,
                       HttpServletResponse response)
         throws IOException, ServletException
     {
+        ResourceBundle rb = ResourceBundle.getBundle("LocalStrings",request.getLocale());
+
         response.setContentType("text/html");
         response.setCharacterEncoding("UTF-8");
 
@@ -55,7 +55,7 @@ public class SessionExample extends HttpServlet {
         out.println("<meta charset=\"UTF-8\" />");
 
 
-        String title = RB.getString("sessions.title");
+        String title = rb.getString("sessions.title");
         out.println("<title>" + title + "</title>");
         out.println("</head>");
         out.println("<body bgcolor=\"white\">");
@@ -77,11 +77,11 @@ public class SessionExample extends HttpServlet {
         out.println("<h3>" + title + "</h3>");
 
         HttpSession session = request.getSession(true);
-        out.println(RB.getString("sessions.id") + " " + session.getId());
+        out.println(rb.getString("sessions.id") + " " + session.getId());
         out.println("<br>");
-        out.println(RB.getString("sessions.created") + " ");
+        out.println(rb.getString("sessions.created") + " ");
         out.println(new Date(session.getCreationTime()) + "<br>");
-        out.println(RB.getString("sessions.lastaccessed") + " ");
+        out.println(rb.getString("sessions.lastaccessed") + " ");
         out.println(new Date(session.getLastAccessedTime()));
 
         String dataName = request.getParameter("dataname");
@@ -91,7 +91,7 @@ public class SessionExample extends HttpServlet {
         }
 
         out.println("<P>");
-        out.println(RB.getString("sessions.data") + "<br>");
+        out.println(rb.getString("sessions.data") + "<br>");
         Enumeration<String> names = session.getAttributeNames();
         while (names.hasMoreElements()) {
             String name = names.nextElement();
@@ -105,10 +105,10 @@ public class SessionExample extends HttpServlet {
         out.print(response.encodeURL("SessionExample"));
         out.print("\" ");
         out.println("method=POST>");
-        out.println(RB.getString("sessions.dataname"));
+        out.println(rb.getString("sessions.dataname"));
         out.println("<input type=text size=20 name=dataname>");
         out.println("<br>");
-        out.println(RB.getString("sessions.datavalue"));
+        out.println(rb.getString("sessions.datavalue"));
         out.println("<input type=text size=20 name=datavalue>");
         out.println("<br>");
         out.println("<input type=submit>");
@@ -119,10 +119,10 @@ public class SessionExample extends HttpServlet {
         out.print(response.encodeURL("SessionExample"));
         out.print("\" ");
         out.println("method=GET>");
-        out.println(RB.getString("sessions.dataname"));
+        out.println(rb.getString("sessions.dataname"));
         out.println("<input type=text size=20 name=dataname>");
         out.println("<br>");
-        out.println(RB.getString("sessions.datavalue"));
+        out.println(rb.getString("sessions.datavalue"));
         out.println("<input type=text size=20 name=datavalue>");
         out.println("<br>");
         out.println("<input type=submit>");


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]