【发布时间】:2017-10-16 14:34:40
【问题描述】:
我正在构建一个简单的 Web 应用程序并尝试使用 servlet 和 RESTful Web 服务将数据插入到数据库中,我收到此错误 HTTP 405 (Method not allowed)。你能给我一些建议吗?
此代码来自网络服务。
@POST
@Path("/2")
@Produces(MediaType.TEXT_PLAIN)
public boolean addBooks(@FormParam("id") int id, @FormParam("isbn")
String isbn, @FormParam("title") String title, @FormParam("author") String
author, @FormParam("genre") String genre, @FormParam("availability") Boolean
availability, @Context HttpServletResponse servletResponse)
throws IOException {
boolean result = DBManager.getInstance().addBook(id, isbn, title, author, genre, availability);
return result;
}
此代码来自 servlet。
WebTarget target = client.target(getBaseURI());
Boolean ok = target.path("rest").path("hello/2").request()
.accept(MediaType.TEXT_PLAIN).get(Boolean.class);
【问题讨论】:
标签: web-services rest jsp servlets post