Question

Ok, I have spent three seven hours googling and testing and I give up, I have to ask for help. I used to develop in Linux and everything was easy, now I use windows and such easy thing like setting correct locale does not work.

I created simple JSP with form:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<form action="save-user" method="post">
    Name: <input type="text" name="name"><br>
    Email: <input type="text" name="email"><br>
    <input type="submit" value="Save">
</form>

And Servlet:

    String name = request.getParameter("name");
    String email = request.getParameter("email");

I receive LeoÅ¡ instead of Leoš. I use WildFly 8.0RC1, Windows 8 czech, firefox.

What I tried already:

  1. request.setCharacterEncoding("UTF-8"); before reading first parameter
  2. Filter with request.setCharacterEncoding("UTF-8");
  3. JVM property -Dfile.encoding=UTF-8
  4. Remove standard JEE stack jars from war
  5. Fix war packaging
  6. Split project to WEB and EJB module

When JPA entity / DAO is deployed then diacritics is mangled. If I comment out entity from servlet and remove JPA entity from war (currently remove OAuthLoginEJB.jar from WEB-INF/lib), then I receive correct encoding. If I add this EJB back then it fails again. Is it JBoss / WildFly bug?

I can provide complete sources: https://drive.google.com/file/d/0B-adlc5KThQDWTdYOEwxOUpTVEU/edit?usp=sharing It is ready to run, you do not even need to type czech letters, as they are prefilled. Thank you

Was it helpful?

Solution

Marko from WildFly dev mailing list pointed me to this defect: https://issues.jboss.org/browse/CDI-411 and this workaround: http://weld.cdi-spec.org/documentation/#3

When I modified my web.xml, it started to work:

<filter>
    <filter-name>EncodingFilter</filter-name>
    <filter-class>cz.literak.demo.oauth.servlets.EncodingFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>EncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
        <filter-name>CDI Conversation Filter</filter-name>
        <url-pattern>/*</url-pattern>
</filter-mapping>

OTHER TIPS

You need to call request.setCharacterEncoding("UTF-8") before first read from request InputStream. Parameters can be read by the filter before you set encoding in your servlet. May be there is some filter in OAuthLoginEJB.jar or in other dependency, which reads parameters first? Typically, this is some parameter for debugging... With Servlet API 3.0, servlets and filters can be registered by annotations, so some filter can be registered despite of empty web.xml.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top