小编Man*_*mma的帖子

HTTP状态415 - 不支持的媒体类型

我正在研究Java restful web服务.在测试restful服务时,我得到的响应对于GET和DELETE方法是正确的,但它不适用于POST和PUT方法.谁能帮我?我写了以下代码:

StudentService.java

@Stateless
@Path("students")
public class StudentService extends StudentServiceLocal<Students> {
    @PersistenceContext(unitName = "RestFulAPIPU")
    private EntityManager em;

    public StudentsFacadeREST() {
        super(Students.class);
    }

    @POST
    @Override
    @Consumes({"application/xml", "application/json"})
    public String create(Students entity) {
        return(super.create(entity));
    }

    @PUT
    @Override
    @Consumes({"application/xml", "application/json"})
    public String edit(@PathParam("id") Students entity) {
        return(super.edit(entity));
    }

    @DELETE    
    @Path("{id}")
    public String remove(@PathParam("id") Integer id) {
        return(super.remove(super.find(id)));
    }

    @GET
    @Path("{id}")
    @Produces({"application/xml", "application/json"})
    public Students find(@PathParam("id") Integer id) {
        return super.find(id);
    }

    @GET
    @Override
    @Produces({"application/xml", "application/json"})
    public List<Students> findAll() {
        return super.findAll();
    } …
Run Code Online (Sandbox Code Playgroud)

java rest web-services http-status-code-415

10
推荐指数
1
解决办法
6万
查看次数

标签 统计

http-status-code-415 ×1

java ×1

rest ×1

web-services ×1