Using Jersey to read form data

后端 未结 2 1499
失恋的感觉
失恋的感觉 2021-01-05 12:20

I\'m developing a web app where i have a form like that

相关标签:
2条回答
  • 2021-01-05 12:49

    Just to keep it simple: in case it is the only request handler mapped to the specific URL (in that case "test") and with the specific HTTP method (POST), you can avoid the usage of @Consumes!

    0 讨论(0)
  • 2021-01-05 13:11

    try this:

    @Path("test")
    @POST
    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
    public String testForm(@FormParam("accept") String accept) {
        return accept;
    }
    

    Multipart is something slightly different, see jersey sample multipart-webapp or see http://www.w3.org/Protocols/rfc1341/7_2_Multipart.html. Your web form is not producing it, so Jersey correctly returns 415 - Unsupported media type, because you don't have any resource which is handling "application/x-www-form-urlencoded" media type.

    0 讨论(0)
提交回复
热议问题