• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlet filter & mapping

 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Quick question, just been looking at Servlet 3.0 and was wondering....

What is the difference plus/minus between mapping a Servlet and Filter a Servlet?

I've always used mappings, and by the looks of the examples I can find Filters are pretty much the same.

Cheers

KS
 
Sheriff
Posts: 67747
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
They're not even remotely alike. A mapping specifies what URL patterns are to be applied to a Servlet, a filter is a type of listener class thats invoked before/after another resource is executed.

Are you asking what the difference is between servlet mappings and filter mappings?
 
Kevin P Smith
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes it was the mappings I was talking about sorry, what's the difference between

<servlet-mapping>
and
<filter-mapping>

What confussed me as well is the way Servlets 3.0 uses Annotations to call these, I was reading that a Filter and Servlet seemed to be the same thing. If it helps this is the tutorial I was looking at:

http://today.java.net/pub/a/today/2008/10/14/introduction-to-servlet-3.html




Then a Servlet class is:




 
Bear Bibeault
Sheriff
Posts: 67747
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
The servlet mappings define what URLs will trigger the servlet, while the filter mappings server the same purpose for what requests the filter will be invoked upon.

This is not a new concept with Servlets 3 -- just the annotations (in lieu of web.xml entries) are.
 
Kevin P Smith
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So just to dumb it down...

The filter-mapping simply maps a URI pattern (/foo) to the filter like the servlet-mapping would map it (/foo) to the Servlet?

So if I was to do a Filter:



and a Servlet:



and executed the URI '/foo' it would call the ServletFilter which would in turn do some 'stuff' under the doFilter method, then call the Servlet then return to the Filter before going off to wherever I have set?

example:
JSP --> ServletFilter --> Servlet --> <wherever>


(If would appear that a quick browse would show that the website I was using is already slightly out of date in the annotations!)
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic