File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

how to deploy servlet at startup

Simon Xu
Ranch Hand

Joined: Aug 16, 2000
Posts: 235
hi,
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>
<servlet-name>???</servlet-name> <servlet-class>DaemonHttpServlet</servlet-class><load-on-startup/>
</servlet>
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,
Simon
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
$TOMCAT_HOME/webapps/test/WEB-INF/web.xml
$TOMCAT_HOME/webapps/test/WEB-INF/classes/DaemonHttpServlet.class
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="http://www.amazon.com/exec/obidos/ASIN/0072127686/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">JSP: The Complete Reference</A><BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072124253/electricporkchop/107-3548162-1137317" 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,
Simon
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Simon,
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.
regds
maha anna
Simon Xu
Ranch Hand

Joined: Aug 16, 2000
Posts: 235
hi, Maha,
Thanks for your expl.
Simon
 
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?