【问题标题】:JAX-RS 405 Method not allowed不允许使用 JAX-RS 405 方法
【发布时间】:2017-06-14 14:52:30
【问题描述】:

我的 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);
}

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();
    }
}

【问题讨论】:

    标签: java jax-rs


    【解决方案1】:

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

    1. 您确定以 POST 的形式发出请求吗?
    2. 您是否将服务器配置为允许向该特定端点发送 POST?
    3. 你在某处有覆盖过滤器的方法吗?

    【讨论】:

      猜你喜欢
      • 2018-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-01
      • 2012-06-29
      • 2013-03-13
      • 2016-03-08
      • 2014-09-19
      相关资源
      最近更新 更多