Hi, >I found when I use method toURI( ) of class File in ServletContextListener, >it will jump contextDestroyed( ) directly. >Did I misuse?
Yes. Exceptions in your contextInitialized() method can result in the container not initializing your context. In fact, the desired behavior IMHO in that case is immediate shutdown, which in turn calls contextDestroyed(). So I think tomcat's doing well in this case. >public class Test implements ServletContextListener { > public Test( ) { > System.out.println("Constructor"); > } > public void contextDestroyed(ServletContextEvent sce) { > System.out.println("Destroy"); > } > public void contextInitialized(ServletContextEvent sce) { > System.out.println("Init"); Add this here: try { File myFile = new File("C:\\"); if(myFile != null) { URI myUri = myFile.toURI(); if(myUri != null) { System.out.println("Test: contextInitialized(sce): myUri = " + myUri.toString()); } } } catch(Exception e) { System.err.println("Test: contextInitialized(sce): exception obtaining myUri: " + e); } > System.out.println("Init finished"); > } >} > In general, if you're doing a servlet context listener, you either: 1. Handle every exception, or 2. Be prepared to have immediate shutdown if you have an uncaught exception. Yoav Shapira Millennium ChemInformatics
This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you.
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>