我用tomcat,在jsp中调用servlet的doPost方法,
如果我改成调用doGet方法时没有错误,
可是我调用doPost时总是出错。
我用WebRun也不好用。老大们我快疯了。

解决方案 »

  1.   

    package commit;import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;public class ServletCommit extends HttpServlet
    {
      private static final String CONTENT_TYPE = "text/html; charset=GBK";
      //Initialize global variables
      public void init() throws ServletException
      {
      }
      //Process the HTTP Get request
      public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
      {
        response.setContentType(CONTENT_TYPE);
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<head><title>ServletCommit</title></head>");
        out.println("<body>");
        out.println("<p>The servlet has received a GET. This is the reply.</p>");
        out.println("</body></html>");
      }  public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
      {
        response.setContentType(CONTENT_TYPE);
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<head><title>ServletCommit</title></head>");
        out.println("<body>");
        out.println("<p>The servlet has received a POST. This is the reply.</p>");
        out.println("</body></html>");
      }
      //Clean up resources
      public void destroy()
      {
      }
    }
      

  2.   

    这是我的JSP
    <form name="form1" method="post" action="/servlet/commit.ServletCommit">
      

  3.   

    If you are using authorization, have you clicked the "Post" checkbox in the web resource definition? Get is the only option checked by default.
      

  4.   

    please make yourself understood.
    i cannot undertand it clearly.
    tanx!
      

  5.   

    public void doPost(HttpServletRequest request,
                          HttpServletResponse response)
            throws IOException, ServletException
        {
            doGet(request, response);
        }
      

  6.   

    405 Method Not Allowed  请求方法(GET、POST、HEAD、DELETE、PUT、TRACE等)对指定的资源不适用。(HTTP 1.1新)
      

  7.   

    后者在你的doPost()中最后加上out.close();试试看!
      

  8.   

    呵呵……
    我有个朋友在学jsp,我教她教了快一个月,直到今天早上,她才连到她的数据库,并可以看到那个jsp的正确显示!
    原因,她用tomcat4.0我没用过,我只记得跟3。2的有区别,今天叫她用tomcat3.2试试看,结果可以了!
    由于一直通过msn和qq教的,很费劲,但终于又拉了一个到java世界了:))