繁体   English   中英

不允许使用JAX-RS 405方法

[英]JAX-RS 405 Method not allowed

我的JAX-RS GET函数运行良好。 我现在正在使用我的POST方法,但这一直给我405错误。 我的资源指向我的DAO。

我的代码有问题吗?

资源

@POST
@Path("/insert")
public void insertIngredient(@QueryParam("Q1") int hoeveelheid, @QueryParam("Q2") String datum,@QueryParam("Q3") String ingredientnaam , @QueryParam("Q4") String gebruikersnaam) {
    IngredientService service = ServiceProvider.getIngredientService();
    service.insertIngredient(hoeveelheid, datum, ingredientnaam, gebruikersnaam);
}

DAO

public void insertIngredient(int hoeveelheid, String datum, String ingredientnaam, String gebruikersnaam) {
    try (Connection con = super.getConnection()) {
        Statement stmt = con.createStatement();
        ResultSet nextId = stmt.executeQuery("SELECT MAX(dagboek_id) FROM dagboek");
        int maxId = nextId.getInt("dagboek_id") + 1;

        stmt.executeQuery("insert into dagboek(dagboek_id, hoeveelheid, datum, fk_ingredientnaam, fk_gebruikersnaam) values('"+maxId+"','" + hoeveelheid + "','" + datum + "','" + ingredientnaam + "','" + gebruikersnaam + "')");

    } catch (SQLException sqle) {
        sqle.printStackTrace();
    }
}

不允许使用HTTP 405方法意味着您获得了正确的终结点,但是没有获得正确的http方法。 它与端点的实现无关。 要检查的常见潜在问题是:

  1. 您确定要通过POST发出请求吗?
  2. 您是否将服务器配置为允许POST到该特定端点?
  3. 您是否在某处覆盖了方法过滤器?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM