File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes how to deploy servlet at startup Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to deploy servlet at startup" Watch "how to deploy servlet at startup" New topic

how to deploy servlet at startup

Simon Xu
Ranch Hand

Joined: Aug 16, 2000
Posts: 235
I have a servlet DaemonHttpServlet and want to load it during startup tomcat. I am using Socket connect applet and servlet.
I know I should modify web.xml file like
<servlet-name>???</servlet-name> <servlet-class>DaemonHttpServlet</servlet-class><load-on-startup/>
is that correct? but i dont have a servlet name for it?
and also is this web.xml file in Root directory?
When I start tomcat, it gives me "can not load servlet name: DaemonHttpServlet.
Please clarify my confusion,
Thank you very much,
Phil Hanna
Ranch Hand

Joined: Apr 05, 2001
Posts: 118
You need to assign a servlet name - why do you say you don't have one? Just use DaemonHttpServlet as the name if you don't have any other preference.
The servlet-class element must contain the fully qualified class name. If the class has no package, it is already correct as is.
The class and the web.xml file can be placed in any web application. For example, if you have Tomcat installed at $TOMCAT_HOME, then the files should be
where "test" can be any web application under $TOMCAT_HOME/webapps (such as "examples", if you don't want to create a new one).
Phil Hanna
Author of :
JSP: The Complete Reference
Instant Java Servlets

Phil Hanna<BR>Sun Certified Programmer for the Java 2 Platform<BR>Author of :<BR><A HREF="" TARGET=_blank rel="nofollow">JSP: The Complete Reference</A><BR><A HREF="" TARGET=_blank rel="nofollow">Instant Java Servlets</A>
Simon Xu
Ranch Hand

Joined: Aug 16, 2000
Posts: 235
hi, Phil,
Thanks for your prompt reply.
Can I load an abstract servlet (class)? Thanks,
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
A sample web.xml which I tested to auto-load is :

We can't auto-load abstract servlet classes since the servlet engine can'e instantiate the servlet and load an 'abstract class' into memory.
maha anna
Simon Xu
Ranch Hand

Joined: Aug 16, 2000
Posts: 235
hi, Maha,
Thanks for your expl.
It is sorta covered in the JavaRanch Style Guide.
subject: how to deploy servlet at startup
Similar Threads
invoking servlet from another servlet
Calling a servlet on startup
cannot load servlet name :
Running a servlet on startup
ClassNotFoundException: can't find my servlet. Can you help?