Lomboz-Eclipse-3.3 + Tomcat-6.0.18 问题

来源:百度知道 编辑:UC知道 时间:2024/05/27 14:45:22
我写了一个Servlet,测试生命周期,程序如下:
public class TestInit extends HttpServlet {
public TestInit() {
System.out.println("Coustruct!");
}
public void init() throws ServletException {
System.out.println("init");
}
public void destroy() {
System.out.println("destroy...");
}
protected void deGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
System.out.println("doGet......");
}
}
但是浏览器访问的时候 老是报错:
HTTP method GET is not supported by this URL

但是我把doGet()方法换成 Service(HttpServletRequest req, HttpServletResponse resp)方法的时候,就一切正常,小弟想知道为什么哈!

这个地址不支持 Get 方法
看你代码里的protected void deGet(HttpServletRequest
是你拷上来出错了 还是 你真正的代码也是 这样啊 deGet //doGet
还有若是通过链接请求的默认是调用doGet 另外 你看看是不是以提交表单的方式的 你这里没写doPost 要是method = post 就该 改成 method = get

另外还有就是
不管是post还是get方法提交过来的连接,都会在service中处理,然后,由service来交由其相应的doPost或doGet方法处理,如果你重写了service方法,就不会再处理doPost或doGet了。