aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Programmatically adding and configuring Servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Programmatically adding and configuring Servlets" Watch "Programmatically adding and configuring Servlets" New topic
Author

Programmatically adding and configuring Servlets

Anup Om
Ranch Hand

Joined: Dec 30, 2009
Posts: 62
Hello,

I am relatively new to Java and have no experience in frameworks. I am trying to understand what it means to add/configure servlets/filters/listeners programmatically. Could somebody please give me a background of what it means, to get me started?

Your help is highly appreciated.

Thanks,


SCJP6
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

There is no standard way to do this. Various containers may provided proprietary interfaces.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Azhakesan Thangamuthu
Greenhorn

Joined: Jul 14, 2008
Posts: 12

What do you mean by add / configure servlets programmatically?
Are you mentioning about Eclipse / any IDE's wizard to create and manage servlets ?
if yes , all the wizard does is the web.xml [class path and servlet name] mapping work for you

Thanks
Alagesh


~ Alagesh (SCWCD ,OCDJWS )
"Education's purpose is to replace an empty mind with an open one"
Liviu Carausu
Ranch Hand

Joined: Oct 07, 2004
Posts: 158
Anu Kota wrote:Hello,

I am relatively new to Java and have no experience in frameworks. I am trying to understand what it means to add/configure servlets/filters/listeners programmatically. Could somebody please give me a background of what it means, to get me started?

Your help is highly appreciated.

Thanks,


Hi,

Up to Servlet 3.0 specification, it was possible to define a servlet only in the Deployment Descriptor (web.xml).


Servlet 3.0 specification (section 4.4.1) defines programmatically ability to add a servlet to a context.
Seen from the API, it looks like this :



You can configure your servlet using the ServletRegistration object. This new feature gives you great flexibility, you can activate and configure
your servlets at runtime depending on different conditions that you are not aware of when you are creating your DD.

Greetings,
Liviu

Oracle Certified Master Java SE6 Developer(SCJD),
OCE JEE 6 JSP and Servlets Developer.
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Note that this is not part of the SCWCD exam, which covers Servlet API 2.4, not Servlet API 3.0.
 
wood burning stoves
 
subject: Programmatically adding and configuring Servlets