Wie übergibt man ein Objekt an eine REST-Web-Ressource mit Jersey

Iam eine neue bie in webservice.Bitte helfen Sie mir.Ich bin versucht, ein Objekt übergeben in webresource mit Jersey Umsetzung.Aber ich habe Fehler

"HTTP Status 405" and description is "The specified HTTP method is not allowed for the requested resource ()."

Erwähnte ich, dass die unter der Objekt -, web-Ressource-Methode,eine Html-Seite

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 versuchen, diesen index.htm.Aber ich bekam Ausnahme.Wie übergibt man ein Objekt in webresource-Methode in Erholsamen webserice mit jersey.Bitte Helfen Sie mir.

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>

Bekam ich folgende Nachricht in der Konsole

SCHWERER: EIN message-body-reader für Java-Typ, Klasse,
com.service.fruitstore.FruitBean, und MIME media Typ,
application/x-www-form-urlencoded wurde nicht gefunden

Bitte helfen Sie mir

haben die Höflichkeit zu schweigen von der Grund von downvoting.

InformationsquelleAutor user1357722 | 2012-08-13

Schreibe einen Kommentar