You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Avatar Zhang (JIRA)" <ji...@apache.org> on 2007/12/07 10:21:34 UTC

[jira] Created: (WW-2361) the default request charEncoding always used.

the default request charEncoding always used.
---------------------------------------------

                 Key: WW-2361
                 URL: https://issues.apache.org/struts/browse/WW-2361
             Project: Struts 2
          Issue Type: Improvement
    Affects Versions: 2.0.11
            Reporter: Avatar Zhang


// SUGGESTION
Index: Dispatcher.java
===================================================================
--- Dispatcher.java	(revision 602010)
+++ Dispatcher.java	(working copy)
@@ -620,10 +620,16 @@
         }
 
         if (encoding != null) {
-            try {
-                request.setCharacterEncoding(encoding);
-            } catch (Exception e) {
-                LOG.error("Error setting character encoding to '" + encoding + "' - ignoring.", e);
+            String encoding2 = request.getCharacterEncoding();
+            if (encoding2 == null) {
+                try {
+                    request.setCharacterEncoding(encoding);
+                    LOG.info("Set Character Encoding to " + encoding + "!");
+                } catch (Exception e) {
+                    LOG.error("Error setting character encoding to '" + encoding + "' - ignoring.", e);
+                }
+            } else {
+                LOG.info("Character Encoding is " + encoding2 + ".");
             }
         }
 


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (WW-2361) the default request charEncoding always used.

Posted by "Don Brown (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/struts/browse/WW-2361?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Don Brown updated WW-2361:
--------------------------

    Fix Version/s:     (was: 2.1.1)
                   2.1.x

Hmm...I'm not sure that the request encoding should always be used.  Could that cause any problems for existing applications?

> the default request charEncoding always used.
> ---------------------------------------------
>
>                 Key: WW-2361
>                 URL: https://issues.apache.org/struts/browse/WW-2361
>             Project: Struts 2
>          Issue Type: Improvement
>    Affects Versions: 2.0.11
>            Reporter: Avatar Zhang
>             Fix For: 2.1.x
>
>
> // SUGGESTION
> Index: Dispatcher.java
> ===================================================================
> --- Dispatcher.java	(revision 602010)
> +++ Dispatcher.java	(working copy)
> @@ -620,10 +620,16 @@
>          }
>  
>          if (encoding != null) {
> -            try {
> -                request.setCharacterEncoding(encoding);
> -            } catch (Exception e) {
> -                LOG.error("Error setting character encoding to '" + encoding + "' - ignoring.", e);
> +            String encoding2 = request.getCharacterEncoding();
> +            if (encoding2 == null) {
> +                try {
> +                    request.setCharacterEncoding(encoding);
> +                    LOG.info("Set Character Encoding to " + encoding + "!");
> +                } catch (Exception e) {
> +                    LOG.error("Error setting character encoding to '" + encoding + "' - ignoring.", e);
> +                }
> +            } else {
> +                LOG.info("Character Encoding is " + encoding2 + ".");
>              }
>          }
>  

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WW-2361) the default request charEncoding always used.

Posted by "Rainer Hermanns (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-2361?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=44232#action_44232 ] 

Rainer Hermanns commented on WW-2361:
-------------------------------------

I'd suggest to use a request encoding filter instead. Try something like this:

    <filter>
        <filter-name>encodingFilter</filter-name>
        <filter-class>
            org.springframework.web.filter.CharacterEncodingFilter
        </filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>INCLUDE</dispatcher>
        <dispatcher>ERROR</dispatcher>
    </filter-mapping>

> the default request charEncoding always used.
> ---------------------------------------------
>
>                 Key: WW-2361
>                 URL: https://issues.apache.org/struts/browse/WW-2361
>             Project: Struts 2
>          Issue Type: Improvement
>    Affects Versions: 2.0.11
>            Reporter: Avatar Zhang
>             Fix For: 2.2.x
>
>
> // SUGGESTION
> Index: Dispatcher.java
> ===================================================================
> --- Dispatcher.java	(revision 602010)
> +++ Dispatcher.java	(working copy)
> @@ -620,10 +620,16 @@
>          }
>  
>          if (encoding != null) {
> -            try {
> -                request.setCharacterEncoding(encoding);
> -            } catch (Exception e) {
> -                LOG.error("Error setting character encoding to '" + encoding + "' - ignoring.", e);
> +            String encoding2 = request.getCharacterEncoding();
> +            if (encoding2 == null) {
> +                try {
> +                    request.setCharacterEncoding(encoding);
> +                    LOG.info("Set Character Encoding to " + encoding + "!");
> +                } catch (Exception e) {
> +                    LOG.error("Error setting character encoding to '" + encoding + "' - ignoring.", e);
> +                }
> +            } else {
> +                LOG.info("Character Encoding is " + encoding2 + ".");
>              }
>          }
>  

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (WW-2361) the default request charEncoding always used.

Posted by "Don Brown (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/struts/browse/WW-2361?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Don Brown updated WW-2361:
--------------------------

    Fix Version/s:     (was: 2.1.x)
                   2.2.x

> the default request charEncoding always used.
> ---------------------------------------------
>
>                 Key: WW-2361
>                 URL: https://issues.apache.org/struts/browse/WW-2361
>             Project: Struts 2
>          Issue Type: Improvement
>    Affects Versions: 2.0.11
>            Reporter: Avatar Zhang
>             Fix For: 2.2.x
>
>
> // SUGGESTION
> Index: Dispatcher.java
> ===================================================================
> --- Dispatcher.java	(revision 602010)
> +++ Dispatcher.java	(working copy)
> @@ -620,10 +620,16 @@
>          }
>  
>          if (encoding != null) {
> -            try {
> -                request.setCharacterEncoding(encoding);
> -            } catch (Exception e) {
> -                LOG.error("Error setting character encoding to '" + encoding + "' - ignoring.", e);
> +            String encoding2 = request.getCharacterEncoding();
> +            if (encoding2 == null) {
> +                try {
> +                    request.setCharacterEncoding(encoding);
> +                    LOG.info("Set Character Encoding to " + encoding + "!");
> +                } catch (Exception e) {
> +                    LOG.error("Error setting character encoding to '" + encoding + "' - ignoring.", e);
> +                }
> +            } else {
> +                LOG.info("Character Encoding is " + encoding2 + ".");
>              }
>          }
>  

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WW-2361) the default request charEncoding always used.

Posted by "Jorge Tapia (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-2361?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=44816#action_44816 ] 

Jorge Tapia commented on WW-2361:
---------------------------------

I'm having problems with this as I have some requests in UTF-8 (GWT interface) and other requests using charset encoding ISO-8859-1.

I have 'UTF-8' in struts.xml so the requests with charset ISO-8859-1 are not correctly understood because the Dispatcher is overwritting the HttpRequest character encoding.

The suggested patch is working for me in version 2.0.11.2.

> the default request charEncoding always used.
> ---------------------------------------------
>
>                 Key: WW-2361
>                 URL: https://issues.apache.org/struts/browse/WW-2361
>             Project: Struts 2
>          Issue Type: Improvement
>    Affects Versions: 2.0.11
>            Reporter: Avatar Zhang
>             Fix For: 2.2.x
>
>
> // SUGGESTION
> Index: Dispatcher.java
> ===================================================================
> --- Dispatcher.java	(revision 602010)
> +++ Dispatcher.java	(working copy)
> @@ -620,10 +620,16 @@
>          }
>  
>          if (encoding != null) {
> -            try {
> -                request.setCharacterEncoding(encoding);
> -            } catch (Exception e) {
> -                LOG.error("Error setting character encoding to '" + encoding + "' - ignoring.", e);
> +            String encoding2 = request.getCharacterEncoding();
> +            if (encoding2 == null) {
> +                try {
> +                    request.setCharacterEncoding(encoding);
> +                    LOG.info("Set Character Encoding to " + encoding + "!");
> +                } catch (Exception e) {
> +                    LOG.error("Error setting character encoding to '" + encoding + "' - ignoring.", e);
> +                }
> +            } else {
> +                LOG.info("Character Encoding is " + encoding2 + ".");
>              }
>          }
>  

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.