I am learning web services with Resteasy
i am doing a simple basic example of rest easy using @FormParam
.
My example works when request method is POST
but does not work when i change the request method toGET
@Path("/form")
public class FromParamService {
@POST
@Path("/add")
public Response addUser(
@FormParam("name") String name,
@FormParam("age") int age) {
return Response.status(200)
.entity("addUser is called, name : " + name + ", age : " + age)
.build();
}
@GET
@Path("/adduser")
public Response addUser1(
@FormParam("name") String name,
@FormParam("age") int age) {
return Response.status(200)
.entity("addUser is called, name : " + name + ", age : " + age)
.build();
}
}
output with GET is
addUser is called, name : null, age : 0
output with POST is
addUser is called, name : Abhi, age : 23
The jsp for GET request is
<html><body>
<form action="rest/form/adduser" method="get">
<p>
Name : <input type="text" name="name" />
</p>
<p>
Age : <input type="text" name="age" />
</p>
<input type="submit" value="Add User" />
</form></body></html>
And Jsp for POST request is
<html><body>
<form action="rest/form/add" method="post">
<p>
Name : <input type="text" name="name" />
</p>
<p>
Age : <input type="text" name="age" />
</p>
<input type="submit" value="Add User" />
</form></body></html>
My question is why i am not able to get values using GET request with @FormParam
?