1

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

4

2 回答 2

2

WildFly 开发邮件列表中的 Marko 向我指出了这个缺陷:https ://issues.jboss.org/browse/CDI-411和这个解决方法:http ://weld.cdi-spec.org/documentation/#3

当我修改我的 web.xml 时,它开始工作:

<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>
于 2014-01-12T20:04:25.163 回答
1

您需要request.setCharacterEncoding("UTF-8")在第一次读取请求 InputStream 之前调用。在您在 servlet 中设置编码之前,过滤器可以读取参数。可能有一些过滤器OAuthLoginEJB.jar或其他依赖项,它首先读取参数?通常,这是用于调试的一些参数...使用 Servlet API 3.0,可以通过注解注册 servlet 和过滤器,因此尽管为空,也可以注册一些过滤器web.xml

于 2014-01-12T11:28:35.417 回答