How can i use a Filter just for servlets and not for jsp?
url-patterns :
/* - this makes the container to call the filter for servlets as well as jsp. *.jsp - this makes the container to call the filter only for jsp.
Is there any way it calls the filter only for servlets..
Since filter is mapped to URL and the mapping is always “positive”, i.e. you cannot say “call this filter unless url is *.jsp) the only solution is create special URLs for either servlets or JSPs.
For example you can map all your servlets to URLs that end with
*.do, e.g.create.do,delete.doetc.Then you can create filter and map it to
*.do:It will work for all servlets (because they are mapped to
*.do) and will not work for JSPs (because they are not mapped to*.do).