Tomcat and HTTPServlet destroy Problem

Discussion in 'Java' started by Marko Langbein, Jun 17, 2005.

  1. Hi,

    i run an tomcat 5.5.9 and jdk-1_5_0_03-windows-i586-p.

    I'm write an small test HttpServlet (with init/destroy), wich on-loaded
    through web.xml at starttime. The init function correctly called by tomcat.

    But uf i close tomcat, the destroy function do not called:

    ----------------snips from servlet code
    public class Controller extends HttpServlet {
    Logging log;

    public void init() throws ServletException {
    super.init();
    buildController();
    return;
    }


    private void buildController() {
    log = new Logging();
    log.log("start");
    }



    public void destroy() {
    try {
    log.log("end");
    } catch (Exception e) {
    }
    return;
    }
    }
    ----------------snips from servlet code

    Have somebody same problems or can verify my problem?

    best regards
    Marko Langbein
    Marko Langbein, Jun 17, 2005
    #1
    1. Advertising

  2. Marko Langbein

    Alan Krueger Guest

    Marko Langbein wrote:
    > But uf i close tomcat, the destroy function do not called:
    >
    > ----------------snips from servlet code

    [...]

    > public void destroy() {
    > try {
    > log.log("end");
    > } catch (Exception e) {
    > }
    > return;
    > }
    > }
    > ----------------snips from servlet code
    >
    > Have somebody same problems or can verify my problem?


    Put a log statement in that catch and see if an exception is being
    thrown. Also put a log statement in init() to be sure it's being called
    properly.
    Alan Krueger, Jun 18, 2005
    #2
    1. Advertising

  3. Alan Krueger wrote:
    > Marko Langbein wrote:
    >
    >> But uf i close tomcat, the destroy function do not called:
    >>
    >> ----------------snips from servlet code

    >
    > [...]
    >
    >> public void destroy() {
    >> try {
    >> log.log("end");
    >> } catch (Exception e) {
    >> }
    >> return;
    >> }
    >> }
    >> ----------------snips from servlet code
    >>
    >> Have somebody same problems or can verify my problem?

    >
    >
    > Put a log statement in that catch and see if an exception is being
    > thrown.

    No exception :(
    > Also put a log statement in init() to be sure it's being called
    > properly.

    Yeah - init() works correctly.

    I think, this is a little bit beta version of tomcat :(

    Regards
    marko
    Marko Langbein, Jun 20, 2005
    #3
  4. Marko Langbein

    Alan Krueger Guest

    Marko Langbein wrote:
    > Yeah - init() works correctly.
    > I think, this is a little bit beta version of tomcat :(


    On that note, what version? How are you launching and closing Tomcat?
    Alan Krueger, Jun 20, 2005
    #4
  5. Alan Krueger wrote:

    > Marko Langbein wrote:
    >
    >> Yeah - init() works correctly.
    >> I think, this is a little bit beta version of tomcat :(

    >
    >
    > On that note, what version?

    This: jakarta-tomcat-5.5.9.tar.gz
    > How are you launching and closing Tomcat?

    startup.bat and shutdown.bat ....

    Greetings
    marko
    Marko Langbein, Jun 21, 2005
    #5
  6. Marko Langbein

    Alan Krueger Guest

    Marko Langbein wrote:
    > Alan Krueger wrote:
    >> On that note, what version?

    >
    > This: jakarta-tomcat-5.5.9.tar.gz
    >
    > > How are you launching and closing Tomcat?

    > startup.bat and shutdown.bat ....


    The following class (based on your post) with the following web.xml
    produce the following log for me on Tomcat 5.5.9 under Windows XP.

    I performed the following set of operations:
    - start Tomcat
    - access servlet
    - stop Tomcat
    - start Tomcat
    - stop Tomcat

    Note the corresponding start/end log entries.

    How are you testing your version of this class? Can you post something
    compilable and a copy of your web.xml?

    ---begin Controller.java---
    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.http.*;

    public class Controller extends HttpServlet {
    public void init() throws ServletException {
    super.init();
    buildController();
    }
    private void buildController() {
    log( "start" );
    }
    protected void service(
    HttpServletRequest req,
    HttpServletResponse resp )
    throws ServletException, IOException {
    log( "service" );
    }
    public void destroy() {
    try {
    log( "end" );
    } catch ( Exception e ) {
    log( e.getMessage() );
    }
    }
    }
    ---end Controller.java---

    ---begin web.xml---
    <!DOCTYPE web-app PUBLIC
    "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
    <servlet>
    <servlet-name>Controller</servlet-name>
    <servlet-class>Controller</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>Controller</servlet-name>
    <url-pattern>/</url-pattern>
    </servlet-mapping>
    </web-app>
    ---end web.xml---

    ---begin log---
    Jun 21, 2005 5:26:56 PM org.apache.catalina.core.ApplicationContext log
    INFO: Controller: start
    Jun 21, 2005 5:26:58 PM org.apache.catalina.core.ApplicationContext log
    INFO: Controller: service
    Jun 21, 2005 5:27:04 PM org.apache.catalina.core.ApplicationContext log
    INFO: Controller: end
    Jun 21, 2005 5:32:04 PM org.apache.catalina.core.ApplicationContext log
    INFO: Controller: start
    Jun 21, 2005 5:32:13 PM org.apache.catalina.core.ApplicationContext log
    INFO: Controller: end
    ---end log---
    Alan Krueger, Jun 21, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Laurent Beaubier \(free.fr\)

    HttpServlet implementation in Tomcat 4.1

    Laurent Beaubier \(free.fr\), Jul 3, 2003, in forum: Java
    Replies:
    1
    Views:
    764
    Sudsy
    Jul 3, 2003
  2. brijesh

    HTTPSERVLET

    brijesh, Jul 31, 2003, in forum: Java
    Replies:
    1
    Views:
    3,329
    Kim Andreassen
    Jul 31, 2003
  3. Raoul Markus

    parameter in HttpServlet.doGet

    Raoul Markus, Aug 21, 2003, in forum: Java
    Replies:
    0
    Views:
    674
    Raoul Markus
    Aug 21, 2003
  4. Eric
    Replies:
    1
    Views:
    772
    Anton Spaans
    Feb 12, 2004
  5. Ook
    Replies:
    2
    Views:
    317
Loading...

Share This Page