写servlet时出现问题HTTP method POST is not supported by this URL如下图所示:

我的出错原因:
public void doPost( HttpServletResponse response,HttpServletRequest request) throws IOException, ServletException { Enumeration e = request.getParameterNames(); PrintWriter out = response.getWriter(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); String value = request.getParameter(name); out.println("<html><body>"+ name + "=" + value + "<hr /><body/><html/>"); }
代码中HttpServletResponse response,HttpServletRequest request
二者位置写反了
解决办法:
改为public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException即可。
HTTP method POST is not supported by this URL
最新推荐文章于 2025-07-19 18:21:52 发布
本文介绍了一位开发者在编写Servlet时遇到的问题:HTTP method POST is not supported by this URL。问题在于doPost方法中HttpServletRequest和HttpServletResponse参数顺序颠倒。正确的顺序应该是先HttpServletRequest再HttpServletResponse。调整参数顺序后,问题得以解决。

1万+

被折叠的 条评论
为什么被折叠?



