HTTP 状态 405 - 此 URL 不支持 HTTP 方法 POST

Posted

技术标签:

【中文标题】HTTP 状态 405 - 此 URL 不支持 HTTP 方法 POST【英文标题】:HTTP Status 405 - HTTP method POST is not supported by this URL 【发布时间】:2012-09-07 21:16:39 【问题描述】:

我尝试发送一些数据,但似乎无法清楚地找到控制器或无法处理请求。

test.jsp

<%@ page errorPage="exception.jsp"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page session="true" import="java.io.*,java.util.*"%>
<%@ page import="eng.ku.sku.exceed_vote.knt.*"%>


  <form name="AddForm" action="addtext" method="POST">
     <input type="hidden" name="todo" value="add">

Add text:<input type="text" name="text" />

    <input type="submit" value="Add">
  </form>

web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee                        

http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<servlet>
<servlet-name>exceed</servlet-name>
<servlet-class>eng.ku.sku.exceed_vote.knt.Controller</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>exceed</servlet-name>
<url-pattern>/addtext</url-pattern>

Controller.java

package eng.ku.sku.exceed_vote.knt;

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;

@WebServlet("/addtext")
public class Controller extends HttpServlet 
    private static final long serialVersionUID = 1L;

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
         throws ServletException, IOException 
      doPost(request, response);  // Same as doPost()
    

    @Override
    protected void doPost(HttpServletRequest request,
         HttpServletResponse response) throws ServletException, IOException 

      // Retrieve the current session, or create a new session if no session exists.
      HttpSession session = request.getSession(true);
      System.out.println("HIIEER");
      // Retrieve the shopping cart of the current session.


      // For dispatching the next Page
      String nextPage = "";
      String todo = request.getParameter("todo");

     // Dispatch to checkout.jsp
     nextPage = "/checkout.jsp";

     response.sendRedirect(nextPage);
     return;
   

我阅读了很多其他主题,但没有找到解决方案。我希望你能帮助我:)

【问题讨论】:

您似乎没有运行您认为正在运行的代码。尝试重建/重新部署/重新启动。顺便问一下,为什么通过 web.xml 和@WebServlet 进行重复的 servlet 注册?在对齐错误的 web.xml 版本后使用其中一个。 错误是什么?你可以添加堆栈跟踪吗? @Chris:它已经在标题中了。当 servlet 的 doPost() 未实现或在方法中的某个位置错误地调用 super.doPost(req, res) 时,这正是您在 webbrowser 中获得的那个。 【参考方案1】:

好的,这是 Tomcat 的错误配置。

它没有同步项目更改。

【讨论】:

以上是关于HTTP 状态 405 - 此 URL 不支持 HTTP 方法 POST的主要内容,如果未能解决你的问题,请参考以下文章

HTTP 状态 405 - 此 URL 不支持 HTTP 方法 GET [重复]

HTTP 状态 405 - 此 URL 不支持 HTTP 方法 POST

Apache Tomcat HTTP 状态 405 - 此 URL 不支持 HTTP 方法 GET [重复]

HTTP 状态 405 - 此 URL 不支持 HTTP 方法 GET

HTTP 状态 405 - 此 URL 不支持 HTTP 方法 GET - RequestDispatcher 出现错误

Servlet 错误:HTTP 状态 405 - 此 URL 不支持 HTTP 方法 GET [重复]