I have to update a Person record having firstName and lastName. User should be able to change it from html form and on submit it should be updated.
Here is my code.
@PUT
@Path("/{userId}")
public Response updatingResource(@FormParam("firstName") String firstName, @FormParam("lastName ") String lastName , @PathParam("userId") String userId){
System.out.println(firstName);
System.out.println(lastName);
return Response.ok().build();
}
the SOP statements prints null. I have been using Mozilla Firefox’s Poster plugin to send PUT request.
I also tried by annotating it with @Consumes(MediaType.APPLICATION_FORM_URLENCODED) but still it is printing null for each values.
How to write and call PUT method that receives these three values. I stumble around lot and found people were asking to use JSON or XML. How can I consume JSON? I would be very greatfull if someone help me to write REST method to update a resource
If I send PUT request using Firefox’s RESTClient and Google’s rest-client I am able to get the form parameters. Both this tool has something like body section where I placed firstName=Amit&lastName=Patel. Also I added header Content-Type as application/x-www-form-urlencoded.I think Firefox’s Poster is buggy. Can anyone suggest me is there any other way I should validate the code or I can trust on first two REST clients?
In addition to annotating your method with
@Consumes(MediaType.APPLICATION_FORM_URLENCODED), you must sendapplication/x-www-form-urlencodedas a content-type. Did you do it?Edited: You can use FormParams only with POST: