【菜鸟询问】servlet中为什么在继承了HttpServlet类之后,其实不能调用super.doGet()和super.doPost()方法呢

重返IT路 2009-01-20 01:24:00
例:

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.因为他不报异常
...全文
675 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
yzzh9 2009-06-04
  • 打赏
  • 举报
回复
楼上两位都说错了,HttpServlet是抽象类,但它没有抽象方法,doGet()和doPost()都不是抽象方法,推荐去看一下源码就明白了。
pxcong007 2009-01-21
  • 打赏
  • 举报
回复
HttpServlet 为抽象类

doGet doPost均为抽象方法

重返IT路 2009-01-21
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 pxcong007 的回复:]
HttpServlet 为抽象类

doGet doPost均为抽象方法


[/Quote]

javax.servlet.http
Class HttpServlet

不是抽象类
withoutme_hw 2009-01-20
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 ChDw 的回复:]
message:HTTP method GET is not supported by this URL
这个信息就是super类中所实现的啊,默认就是打印这样的语句
[/Quote]

原来如此。。。
ChDw 2009-01-20
  • 打赏
  • 举报
回复
message:HTTP method GET is not supported by this URL
这个信息就是super类中所实现的啊,默认就是打印这样的语句
hy0231 2009-01-20
  • 打赏
  • 举报
回复
GET POST请求你总要处理一个。
重返IT路 2009-01-20
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 ChDw 的回复:]
message:HTTP method GET is not supported by this URL
这个信息就是super类中所实现的啊,默认就是打印这样的语句
[/Quote]

哦 原来这样的啊那为什么 调用了父类的方法 子类后面的程序就不执行了?

67,550

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧