aspose file tools*
The moose likes Servlets and the fly likes Need to access the Filter config in web.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Need to access the Filter config in web.xml" Watch "Need to access the Filter config in web.xml" New topic
Author

Need to access the Filter config in web.xml

Veronica Lalchandani
Greenhorn

Joined: Feb 03, 2010
Posts: 2
Is there some API, to read the filters and the filter-mapping defined in the web.xml?
Ninad Kulkarni
Ranch Hand

Joined: Aug 31, 2007
Posts: 791

@Veronica
Welcome to JavaRanch.
What you want to know exactly? About xml file reading or filter mapping?


SCJP 5.0 - JavaRanch FAQ - Java Beginners FAQ - SCJP FAQ - SCJP Mock Tests - Tutorial - JavaSE7 - JavaEE6 -Generics FAQ - JLS - JVM Spec - Java FAQs - Smart Questions
Charles 'King
Ranch Hand

Joined: Jul 05, 2009
Posts: 56

Veronica Lalchandani wrote:Is there some API, to read the filters and the filter-mapping defined in the web.xml?


If you have access to the DD, why do you need to read it during run-time? Are you interested in accessing filter init parameters?
Kris Schneider
Ranch Hand

Joined: Feb 14, 2001
Posts: 71
If you're using a Java EE 6 (Servlet 3.0) containter, take a look at the ServletContext.getFilterRegistrations method.
Charles 'King
Ranch Hand

Joined: Jul 05, 2009
Posts: 56

Kris Schneider wrote:If you're using a Java EE 6 (Servlet 3.0) containter, take a look at the ServletContext.getFilterRegistrations method.


And if you're not and you must know all filter names, simply put the names or class names in a filter init parameter of sorts and create your map in a servlet context listener. Seems like a lot of work just for a map of filters
Veronica Lalchandani
Greenhorn

Joined: Feb 03, 2010
Posts: 2
I had a requirement to get the filters ... Thanks everyone for your help
Charles 'King
Ranch Hand

Joined: Jul 05, 2009
Posts: 56

Veronica Lalchandani wrote:I had a requirement to get the filters ... Thanks everyone for your help


If your component is in the same web context, use the Servlet context method getResourceAsStream("/WEB-INF/web.xml") - Remember to wrap the InputStream into your favorite reader to read each line of the DD -- good luck
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need to access the Filter config in web.xml