gpt4 book ai didi

servlets - doPost super 导致 - HTTP 状态 405

转载 作者:行者123 更新时间:2023-12-04 04:33:26 25 4
gpt4 key购买 nike

到目前为止,我认为调用 super.doPost(req, resp) 是一种常见的做法。来自您的 servlet 的 doPost(req, resp){}但这是我面临的问题 -
我有一个非常简单的 servlet,它有一个 doPost(req, resp) 并且因为它是从 eclipse 自动生成的方法,所以它有 super.doPost(req, resp)这很好,因为它正在调用其 parent 的 doPost() 但我得到了

HTTP Status 405 - HTTP method GET is not supported by this URL whenever the servlet was hit. I went through a lot of post and this post



一直在谈论同样的问题,建议的解决方案之一是删除 super.doGet()。

我对我的 Post 方法做了同样的事情,令我惊讶的是它有效!!!!

我找不到一个合乎逻辑的原因。有人可以解释发生了什么吗?
为何是

405 flashing due to call of super.doPost().



谢谢,
索拉布。

最佳答案

HttpServlet.doPost 的默认实现返回 405 错误(不允许的方法)。您必须执行 doPost方法,如果你想在你的 servlet 中支持 POST 方法。

这是code of HttpServlet.doPost :

protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String protocol = req.getProtocol();
String msg = lStrings.getString("http.method_post_not_supported");
if (protocol.endsWith("1.1")) {
resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, msg);
} else {
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);
}
}

关于servlets - doPost super 导致 - HTTP 状态 405,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20159108/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com