null in FormParam with “charset=UTF-8” in Jersey 2.0

别来无恙 提交于 2019-12-25 07:08:01

问题


I'm currently working on an AngularJS project and I'm calling some rest services using content-type "application/x-www-form-urlencoded;".

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>

Everthing work fine on Chrome and IE7. My problem is Firefox who add mystically "charset=UTF-8" in the content type.

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

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,

I tried with this headers

@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.


回答1:


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



来源:https://stackoverflow.com/questions/17972878/null-in-formparam-with-charset-utf-8-in-jersey-2-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!