私は webservice の初心者です。助けてください。Jersey 実装を使用して webresource にオブジェクトを渡そうとしていますが、エラーが発生しました。
"HTTP Status 405" and description is "The specified HTTP method is not allowed for the requested resource ()."
以下のオブジェクト、Webリソースメソッド、Htmlページについて言及しました
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 サービス:-
@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>
このindex.htmを実行しようとしていますが、例外が発生しました.Jerseyを使用してRestfull WebサービスでオブジェクトをWebリソースメソッドに渡す方法.助けてください.
アップデート :-
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;
}
インデックス.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>
コンソールに以下のメッセージが表示されました
SEVERE: Java タイプ、クラス com.service.fruitstore.FruitBean、および MIME メディア タイプ、application/x-www-form-urlencoded のメッセージ本文リーダーが見つかりませんでした。
私を助けてください