Author: cbrisson
Date: Sat Oct 15 07:27:26 2016
New Revision: 1765021

URL: http://svn.apache.org/viewvc?rev=1765021&view=rev
Log:
[tools] let VelocityViewServlet set request encoding to Velocity input encoding

Modified:
    
velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/VelocityViewServlet.java

Modified: 
velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/VelocityViewServlet.java
URL: 
http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/VelocityViewServlet.java?rev=1765021&r1=1765020&r2=1765021&view=diff
==============================================================================
--- 
velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/VelocityViewServlet.java
 (original)
+++ 
velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/VelocityViewServlet.java
 Sat Oct 15 07:27:26 2016
@@ -22,6 +22,7 @@ package org.apache.velocity.tools.view;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
 import java.io.Writer;
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
@@ -205,6 +206,9 @@ public class VelocityViewServlet extends
         Context context = null;
         try
         {
+            // prepare needed request and response attributes and properties
+            initRequest(request, response);
+        
             // then get a context
             context = createContext(request, response);
 
@@ -237,6 +241,34 @@ public class VelocityViewServlet extends
         }
     }
 
+    /**
+     *  <p>
+     *    Request and response initialization. Default version does
+     *    only one thing: set request POST parameters encoding to
+     *    Velocity input encoding.
+     *  </p>
+     *
+     *  @param request  HttpServletRequest object containing client request
+     *  @param response HttpServletResponse object for the response
+     */
+    protected void initRequest(HttpServletRequest request, HttpServletResponse 
response) throws IOException
+    {
+        // adjust HTTP encoding: use value provided for input.encoding
+        // (this affects POST parameters only;
+        // to adjust GET URI and parameters encoding, please refer to your
+        // J2EE container documentation (for instance, under tomcat,
+        // use <Connector ... URIEncoding="UTF-8">)
+        try
+        {
+            request.setCharacterEncoding(getVelocityProperty("input.encoding", 
"UTF-8"));
+        }
+        catch (UnsupportedEncodingException uee)
+        {
+            error(request, response, uee);
+            throw uee;
+        }
+    }
+        
 
     /**
      * <p>This was a common extension point, but now it is usually


Reply via email to