Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to deploy servlet at startup

 
Simon Xu
Ranch Hand
Posts: 235
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Simon Xu
Ranch Hand
Posts: 235
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, Phil,
Thanks for your prompt reply.
Can I load an abstract servlet (class)? Thanks,
Simon
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 235
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, Maha,
Thanks for your expl.
Simon
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic