This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Can we dynamicaly load servelt without giving entry in web.xml?
In our web application we have sevral servlets in our application and at particular point of time few of them might be active and few of them diactivate means their service are not available and this acitivation and deactivation can be done by admin of application.
For example this point of time say 3 servelts are available for service and 4 are not available and admin changes activ and deactivate flag and activates one more servlet. now can we[application] automatically load or add that newly activated servlet to application context?
Regards,<br />BulletProof Monk.<br /> <br />"Nthing the Mind of man can Conceive<br />and Believe,It can achieve"
base/serviceproviderServlet2 - points to serviceproviderServlet2
Now admin can have ability deactivate or activate this 'serviceproviderServlet2' at and point of time, that means when admin deactivt some servlet application need to unload deactivated servlet and load activated servlet.
One is to look for a form parameter and use that to determine which servlet to use.
Struts does this by mapping the extension ".do". All requests that end in ".do" go to a controller servlet. The servlet then reads the the URI, strips out the ".do" part, and forwards according to what's left.
Another way is to map all of your action servlets to a particular directory. Such as: actions/* Then, in the controller, parse the URI and look for the last part of the URI and use that string to steer your command pattern.
I have a very crude and simple example of this (using form parameters) on my site. http://simple.souther.us Look for Simple Command.
Joined: Jan 24, 2005
Thank a lot Ben.
I deploy SimpleServlet.war. as you can see there we have entry for SimpleServlet in web.xml.
Can you instantiate,load and unload this SimpleServlet without putting entry in web.xml?
but here in our application those servlets as some 3rd party servlets that we allready have in side our appication but its instantiation and loading to application context should be in hand of application itself.
dont we need an entry for every serlvet inside web.xml? As far as I can recollect when we make an entry in web.xml , only then the servlet config object will be available to the servlet object... If there is no entry in web.xml , how will the app differentiate what is a servlet and what are normal objects.
We can use the invoker servlet for this case.We do not need to configure the servlet in the web.xml and use the invoker servlet for this.Make sure to activate the invoker servlet in the web.xml at /conf.
Originally posted by Kamlesh Thakkar: dont we need an entry for every serlvet inside web.xml? As far as I can recollect when we make an entry in web.xml , only then the servlet config object will be available to the servlet object... If there is no entry in web.xml , how will the app differentiate what is a servlet and what are normal objects.
You can pass setting (or even the whole config object if you choose) from the front controller to the other servlets (action classes).
Originally posted by Rahul Bhattacharjee: We can use the invoker servlet for this case.We do not need to configure the servlet in the web.xml and use the invoker servlet for this.Make sure to activate the invoker servlet in the web.xml at /conf.
The invoker servlet is a Tomcat feature which has been, in effect, deprecated. It still exists but it's servlet entry has been commented out of the config files.
There were a lot of reasons for this. Rahul already mentioned one (You can't use init params configured in web.xml when using the Invoker). To read the other reasons why you shouldn't use it, see: http://faq.javaranch.com/view?InvokerServlet