Tomcat and HTTPServlet destroy Problem

M

Marko Langbein

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
 
A

Alan Krueger

Marko said:
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.
 
M

Marko Langbein

Alan said:
Marko said:
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
 
A

Alan Krueger

Marko said:
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?
 
A

Alan Krueger

Marko said:
This: jakarta-tomcat-5.5.9.tar.gz

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---
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top