• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Can we turn on and off the servlets in web.xml?

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it possible to turn on and off the particular servlets from web.xml ((ie) Disable or enable particular servlet in web.xml) externally without updating the data manually in web xml?
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not with anything already available from the Servlet API.

What's the use case? Perhaps there's a way to achieve what you are actually trying to accomplish.
 
nacassa sam
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply, I need to disable or enable the servlets depending on the input data for example, if its a production eniv, I need few servlets to be available and for test i doesn't require them, so basically i need to update the servlets in web xml to support my configuration.

Is there any possibility of using load-on-startup values and setting this?
 
Sheriff
Posts: 22802
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps you could do this with a front controller and context attributes that you can set through some servlet, but it would require your entire web application to be rewritten to use that front controller.
 
Marshal
Posts: 28296
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What would it mean to "disable" a servlet? Would that require sending a 404 error response to any requests for that servlet?

Anyway keeping track in the application context of which servlets were "disabled", along with a filter to enforce that disabling, might also be a solution.
 
nacassa sam
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, It does not need to send a 404 message, the scenario here is, I have a bunch of servlets in web xml file and depending on the input data my web xml should be modified such that only servlets required for my app based on the input should be present in the web xml and other servlets in the web xml should be disabled.
 
Rob Spoor
Sheriff
Posts: 22802
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But what does "disabled" mean? What should happen if you still try to access that servlet?
 
Bear Bibeault
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like this a build-time issue not a run-time issue. If you are building for the test environment, create a web.xml that includes the extra servlets. For a production build, leave them out of the web.xml.
 
nacassa sam
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Rob Those servlets should not be available for access in that particular environment.
 
Bear Bibeault
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

nacassa sam wrote:@Rob Those servlets should not be available for access in that particular environment.


Which brings us back to my reply. If they don't need to be there, don't put them there in the first place.
 
nacassa sam
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah thanks for the info, but i was trying to find whether there is a possibility of having one web xml and the servlets related to the app in it as like i have now, and to turn off the servlets depending on the environment selected, without doing it manually.

But guess from your answers, there is no option to do so, Am i right?
 
Paul Clapham
Marshal
Posts: 28296
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's assume that to "turn off" a servlet means to not include it in the web.xml file -- that seems the most likely thing for it to mean based on what I've seen so far.

And let's assume that "doing it manually" means "using a text editor to modify the web.xml file" -- although it could mean a lot of other things.

Then no, you don't have to "do it manually". You could write an application which transformed a master version of the web.xml file into a subset suitable for your various applications.
 
Bear Bibeault
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you doing your build? Ant has plenty of options for doing this sort of thing.
 
nacassa sam
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using Maven for my build.
 
Yes, of course, and I accept that blame. In fact, i covet that blame. As does this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic