Iam a new bie in webservice.Please help me.I am trying to pass an object into webresource using Jersey Implementation.But i got error
"HTTP Status 405" and description is "The specified HTTP method is not allowed for the requested resource ()."
I mentioned the below object ,web resouce method,Html page
FruitBean:-
@XmlRootElement(name="fruitbean")
public class FruitBean {
private long id;
private String name;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
FruitStore Service:-
@Path("fruitstore")
public class FruitStore {
@PUT
@Path("checkIDByObject")
@Consumes("application/xml")
public void loadObject(FruitBean bean){
System.out.println("====================");
System.out.println("Fruit ID"+bean.getId()+" Name"+bean.getName());
}
}
Index.htm:-
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Test Jax-RS Object</title>
</head>
<body>
<form action="services/fruitstore/checkIDByObject" method="POST">
<table>
<tr>
<td>ID:</td>
<td><input type="text" name="id"></td>
</tr>
<tr>
<td>Name:</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td><input type="submit" Value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>
Iam trying to run this index.htm.But i got exception.How to pass an object into webresource method in Restfull webserice using jersey.Please Help me.
Update :-
FruitStore Service:-
@Path("fruitstore")
public class FruitStore {
@POST
@Path("checkIDByObject")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public void loadObject(FruitBean bean){
System.out.println("====================");
System.out.println("Fruit ID"+bean.getId()+" Name"+bean.getName());
}
}
FruitBean:-
@XmlRootElement(name="fruitbean")
public class FruitBean {
private long id;
private String name;
@XmlAttribute
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@XmlAttribute
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
Index.html:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Test Jax-RS Object</title>
</head>
<body>
<form action="services/fruitstore/checkIDByObject" method="POST" enctype="application/x-www-form-urlencoded">
<table>
<tr>
<td>ID:</td>
<td><input type="text" name="id"></td>
</tr>
<tr>
<td>Name:</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td><input type="submit" Value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>
I got below message in the console
SEVERE: A message body reader for Java type, class com.service.fruitstore.FruitBean, and MIME media type, application/x-www-form-urlencoded, was not found
Please help me