我是 webservice 的新成员。请帮助我。我正在尝试使用 Jersey 实现将对象传递到 webresource。但我遇到了错误
"HTTP Status 405" and description is "The specified HTTP method is not allowed for the requested resource ()."
我提到了下面的对象,网络资源方法,HTML页面
果豆:-
@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;
}
}
水果店服务:-
@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());
}
}
索引.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>
我正在尝试运行此 index.htm。但我遇到了异常。如何使用 jersey 将对象传递给 Restfull webserice 中的 webresource 方法。请帮助我。
更新 :-
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());
}
}
果豆:-
@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;
}
索引.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>
我在控制台中收到以下消息
严重:找不到 Java 类型、com.service.fruitstore.FruitBean 类和 MIME 媒体类型 application/x-www-form-urlencoded 的消息正文阅读器
请帮我