REST @FormParam is null

橙三吉。 提交于 2019-12-07 02:36:27

AFAIK, there is no Jersey (JAX-RS) mechanism to parse JSON into form data. Form data should be in the form of something like

firstName=Stack&lastName=Overflow (or in your case clientName=someName)

where firstName and lastName are generally then name attribute value in the form input elements. You can use jQuery to easily serialize the field values, with a single serialize() method.

So you might have something that looks more along the lines of something like

<form id="post-form" action="/path/to/resource">
    Client Name: <input type="text" name="clientName"/>
</form>
<input id="submit" type="button" value="Submit"/>
<script>
    $("#submit").click(function(e) {
        $.ajax({
            url: $("form").attr("action"),
            data: $("form").serialize(),
            type: "post",
            success: processResponse,
            contentType: "application/x-www-form-urlencoded"
        });
    });
    function processResponse(data) {
        alert(data);
    }
</script>

Have you defined the Requestmapping like this:

@POST
@Path("/submitclient") // your request mapping for 'subUrl'
public Object persistResetPasswordLogs(@FormParam("clientName") String clientName)

and html:

<form action="submitclient" method="post">
    ...
</form>

Also look at your json object. I believe you should send something like this:

var loginData = {
    clientName: "dit" // get it from input
};

?

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