Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Filters  RSS feed

Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
while i am working with FILTERS in java,

1) Is it compulsary to have a servlet when working with filter and

2) if i want to call a specific servlet using filters then how should we proceed.

please explain me with an example if possible along with deployment descriptor
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No it's not mandatory to have a servlet in order to use a filter.

Say we have a filter:


This will filter ALL requests received, irrespective of the resource requested. Images, pages, stylesheets, the works.

I'm not entirely sure what you ment by calling a servlet using a filter, but I suspect you either want to redirect to the servlet url, or request a servlet resource while processing a user request.

1) Redirecting:
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException

2) Requesting a servlet:
{ url = new"htpp://myserver/myServlet.go");
InputStream myStream = url.openStream();
//Code to read servlets' response from the myStream InputStream
It's a pleasure to see superheros taking such an interest in science. And this tiny ad:
Programmatically Create PDF Using Free Spire.PDF with Java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!