HTTP method POST is not supported by this URL解決

來源:互聯網
上載者:User

標籤:exception   send   沒有   stat   pattern   void   class   uil   stream   

今天寫了個非常簡單的setvlet想測試些東西,寫好了後用postman請求報錯,報錯內容如下

{    "timestamp": 1504170113588,    "status": 405,    "error": "Method Not Allowed",    "message": "HTTP method POST is not supported by this URL",    "path": "/vincent/aaa"}

但是我的控制台還是答應了我的請求內容,百思不得其解,最後發現是因為沒有把調用父類的post方法刪掉

My Code如下

@WebServlet(urlPatterns = "/aaa")public class MyServlet extends HttpServlet{    @Override    protected void doGet(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {        super.doGet(request, resp);    }    @Override    protected void doPost(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {        InputStream inputStream = request.getInputStream();        BufferedReader in=new BufferedReader(new InputStreamReader(request.getInputStream()));        StringBuilder sb = new StringBuilder();        String xmlHead = "";        String xmlContent="";        String line = null;        while ((line = in.readLine()) != null) {            sb.append(line);        }        System.out.println(sb);        super.doPost(request, resp);    }}
 super.doPost(request, resp);的源碼如下
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(405, msg);        } else {            resp.sendError(400, msg);        }    }

有沒有發現,無論你的請求怎樣,他都報錯的。

HTTP method POST is not supported by this URL解決

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.