例: public class TextHttpServlet extends HttpServlet{

public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException{
super.doGet(req, res); //1
// ....
}

public void doPost(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException{
super.doPost(req, res);//2
// ...
}
}

如果光写1,就报一个message:HTTP method GET is not supported by this URL
如果光写2,就报一个message:HTTP method POST is not supported by this URL
两个都写,就报一个异常:java.lang.IllegalStateException本人初学者,用eclipse自动生成代码。不小心没把那个去了,让我调了半小时。最后才知道这个问题,但不知道为什么会这样。请各位大牛解答下~~~
这个问题还真是不好调试,尤其是1,2.因为他不报异常

解决方案 »

  1.   

    GET  POST请求你总要处理一个。
      

  2.   

    message:HTTP method GET is not supported by this URL 
    这个信息就是super类中所实现的啊,默认就是打印这样的语句
      

  3.   

    HttpServlet 为抽象类doGet doPost均为抽象方法
      

  4.   


    javax.servlet.http
    Class HttpServlet不是抽象类
      

  5.   

    楼上两位都说错了,HttpServlet是抽象类,但它没有抽象方法,doGet()和doPost()都不是抽象方法,推荐去看一下源码就明白了。