在FormParam中为null并带有"charset = UTF-8"的字符;在Jersey 2.0中 [英] null in FormParam with "charset=UTF-8" in Jersey 2.0
问题描述
我目前正在从事AngularJS项目,并使用内容类型"application/x-www-form-urlencoded;"来调用一些其他服务.
I'm currently working on an AngularJS project and I'm calling some rest services using content-type "application/x-www-form-urlencoded;".
在服务器端,我在2.0版中使用Jersey.这是我的Maven依赖项.
On server side I use Jersey in version 2.0. This is my maven dependency.
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.0</version>
</dependency>
在Chrome和IE7上一切正常.我的问题是Firefox,他们在内容类型中神秘地添加了"charset = UTF-8".
Everthing work fine on Chrome and IE7. My problem is Firefox who add mystically "charset=UTF-8" in the content type.
我进行了一些测试,如果我使用POSTMAN并在内容类型中设置"application/x-www-form-urlencoded; charset = UTF-8",则Jersey的所有FormParam参数都为空
I made some test and if I use POSTMAN and set "application/x-www-form-urlencoded; charset=UTF-8" in the content type, Jersey has null in all FormParam parameters
这是我的Java方法的头文件
This is the header of my method in java
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("movements/")
public Response movements(
@FormParam("COMPTE_NO") String COMPTE_NO,
@FormParam("COMPTE_BIDULE") String COMPTE_BIDULE,
@FormParam("COMPTE_MACHIN") String COMPTE_MACHIN,
我尝试使用此标题
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("movements/")
@Consumes({MediaType.APPLICATION_FORM_URLENCODED + ";charset=UTF-8",
MediaType.APPLICATION_FORM_URLENCODED + "; charset=UTF-8",
MediaType.APPLICATION_FORM_URLENCODED})
public Response movements(
@FormParam("COMPTE_NO") String COMPTE_NO,
@FormParam("COMPTE_BIDULE") String COMPTE_BIDULE,
@FormParam("COMPTE_MACHIN") String COMPTE_MACHIN,
我遇到了完全相同的问题.你有想法吗 ? 预先感谢.
And I had exactly the same problem. Do you have an idea ? Thanks in advance.
推荐答案
这个问题是重复的.可以在中找到响应在Content-Type中指定字符集时,Jersey和@FormParam不起作用
This question is a duplication. A response can be found on Jersey and @FormParam not working when charset is specified in the Content-Type
在票证上可以找到泽西票证和过滤器的解决方法
Jersey ticket and filter has a workaround can be found on the ticket
这篇关于在FormParam中为null并带有"charset = UTF-8"的字符;在Jersey 2.0中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!