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 Registering a Servlet at runtime Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Registering a Servlet at runtime" Watch "Registering a Servlet at runtime" New topic
Author

Registering a Servlet at runtime

Alexey Gor
Greenhorn

Joined: Jul 13, 2004
Posts: 27
Ranchers,

Is it possible to register a servlet at runtime without specifying it in web.xml? We are using Tomcat 5.5.12... Thank you.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39549
    
  27
It is possible to access servlets that are not specified in web.xml by their classname; the InvokerServlet does this. That mechanism has many drawbacks, and is generally frowned upon, but it does work.


Ping & DNS - updated with new look and Ping home screen widget
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Tomcat suports hot deployment, so you could add the servlet to the WAR, including the mapping, and use the management console to redeploy the WAR file. It wouldn't be perfect since it would first unload the application then restart it.
dema rogatkin
Ranch Hand

Joined: Oct 09, 2002
Posts: 294
Some servlet containers support legacy type of servlet definition using properties file. I found that convinient for embedded deployment, for example Sharp Zaurus. I believe old versions of Tomcat support this way.


Tough in space?, <a href="http://tjws.sf.net" target="_blank" rel="nofollow">Get J2EE servlet container under 150Kbytes here</a><br />Love your iPod and want it anywhere?<a href="http://mediachest.sf.net" target="_blank" rel="nofollow">Check it here.</a><br /><a href="http://7bee.j2ee.us/book/Generics%20in%20JDK%201.5.html" target="_blank" rel="nofollow">Curious about generic in Java?</a><br /><a href="http://7bee.j2ee.us/bee/index-bee.html" target="_blank" rel="nofollow">Hate ant? Use bee.</a><br /><a href="http://7bee.j2ee.us/addressbook/" target="_blank" rel="nofollow">Need contacts anywhere?</a><br /><a href="http://searchdir.sourceforge.net/" target="_blank" rel="nofollow">How to promote your business with a search engine</a>
saikrishna cinux
Ranch Hand

Joined: Apr 16, 2005
Posts: 689
Originally posted by David O'Meara:
Tomcat suports hot deployment, so you could add the servlet to the WAR, including the mapping, and use the management console to redeploy the WAR file. It wouldn't be perfect since it would first unload the application then restart it.


hi,
u r saying that tomcat has got hot diploymen..??
but i use tomcat 5.0 i never came thru this. i do thi manually all the time if modif any servlet..
manually means i modify web.xml file and save that file.. so it will redeploy the servlet..
r u sure that tomcat redeploy the files if i change something in the servlet??? imwan without saving the web.xml file ?

please reply soooooon
cinux


A = HARDWORK B = LUCK/FATE If C=(A+B) then C=SUCCESSFUL IN LIFE else C=FAILURE IN LIFE
SCJP 1.4
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

I do not believe it supports hot deployment of servlet classes, but if you (for example) run from a WAR and then update the WAR file, the application is unloaded and reloaded.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Registering a Servlet at runtime
 
Similar Threads
include() methos of RequestDispatcher?
Objective 2.5 - memory/gc
Passing runtime parameters to EJB
Is there a way to check the methods calling another method
== operator returns true for Strings