Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
nacassa sam
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
Rob Spoor
Sheriff
Pie
Posts: 20546
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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.
 
Paul Clapham
Sheriff
Posts: 21126
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
  • 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
Pie
Posts: 20546
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But what does "disabled" mean? What should happen if you still try to access that servlet?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
@Rob Those servlets should not be available for access in that particular environment.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Sheriff
Posts: 21126
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
I am using Maven for my build.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic