首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

servlet中init方法可以执行,但是doGet方法不能执行解决办法

2012-03-23 
servlet中init方法可以执行,但是doGet方法不能执行为什么servlet中init方法可以执行,但是doGet方法不能执

servlet中init方法可以执行,但是doGet方法不能执行
为什么servlet中init方法可以执行,但是doGet方法不能执行

Java code
public class TestServlet extends HttpServlet {    private static final long serialVersionUID = 1L;    /**     * Default constructor.      */    public TestServlet() {         TODO Auto-generated constructor stub        super();    }    /**     * @see Servlet#init(ServletConfig)     */    public void init(ServletConfig config) throws ServletException {        // TODO Auto-generated method stub        System.out.println("Hello!");    }    /**     * @see Servlet#destroy()     */    public void destroy() {        // TODO Auto-generated method stub    }    /**     * @see Servlet#getServletConfig()     */    public ServletConfig getServletConfig() {        // TODO Auto-generated method stub        return null;    }    /**     * @see Servlet#getServletInfo()     */    public String getServletInfo() {        // TODO Auto-generated method stub        return null;     }    /**     * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)     */    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        // TODO Auto-generated method stub    }    /**     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)     */    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        // TODO Auto-generated method stub            System.out.println("doGet");    }    /**     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)     */    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        // TODO Auto-generated method stub    }}

控制台打印出Hello了,但是没有打印出doGet

[解决办法]
呵呵,你把service方法去掉吧,如果没有doget和dopost他默认的就是调用service方法。
[解决办法]
我去,你把service方法覆盖了!自己查看下文档或源码看看service方法的作用吧,最好不要覆盖它!

热点排行