我用Tomcat,运行Servlet时,只要用doPost()方法就报错。
HTTP Status 405 - HTTP method GET is not supported by this URL而用doGet()则正常,为什么?

解决方案 »

  1.   

    原来一直用IDE没有单独用过Tomcat,没注意过这个问题,请高手解答!
      

  2.   

    你的doPost方法体是什么?doGet呢?
    这个错误看上去应该是你没有写doGet方法,而请求是通过GET方式发起的而不是POST
      

  3.   

    我的也是这个问题,为什么?我的代码如下:
    public class Sayhi1 extends HttpServlet
    {
    public void init(ServletConfig config)throws ServletException
    {
    super.init(config);
    }
        public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
    {
            response.setContentType("Text/html;charset=GB2312");
    PrintWriter out=response.getWriter();
    request.setCharacterEncoding("GB2312");

    out.println("<html><head><title>Say hi</title><head><body>");

    out.println("welcome!");
    out.println("</body></html>");
    out.close();
    }
       
    public void destroy(){}
    }
      

  4.   

    在servlet中你們只寫了doPost()方法,而沒有寫doGet()方法對吧?這個時候,如果你們在表單中提交數據的時候,如果是get方法提交,那麼就找不到你們所要轉向的jsp或者html頁面,也就是報上述錯誤:HTTP Status 405 - HTTP method GET is not supported by this URL多寫點就知道這些類似於404,405,500...的錯誤了。建議初學時最好還是用一些tomcat為好,這樣也方便將來用快速開發工具的時候更快速!!!
      

  5.   

    我在页面中是用post 提交的啊