Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why is my Filter called for every image, included jsp and the main jsp?

 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I noticed that when i have a JSP page with jsp:include calls and images, the filter gets called for every include and image! Why is this? How do I stop this and make it called once for the entire page?

I read somewhere that you can put an attribute in the request object and then read it to see if it's your second time around. It doesn't work!! This covers jsp:includes BUT images are being treated as fully new requests!! What's going on?
[ October 27, 2006: Message edited by: Dan Bizman ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64980
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You probably have a URL mapping for the filter that is too broad.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64980
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dan Bizman:
BUT images are being treated as fully new requests!!


Yes, that's how HTML and HTTP work.
 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
You probably have a URL mapping for the filter that is too broad.


So the only way to get it to not call the filter multiple times is to put the images, scripts outside the "folder hierarchy" of the pages?

And why can't I find a way to let the filter know it's been called before? I understand they're treated as separate requests by the browser, but is there any way to know that they're really sup-parts of a page?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64980
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, HTTP is stateless protocol.

You need to map your filter appropriately.

The use of a front controller really helps in this regard as servlet requests to this controller can be mapped to the filter, and all other ancillary requests are not.
 
Eddy Lee Sin Ti
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can try to use the <dispatcher> under the <filter-mapping> element to further controler how your filter is activated. Note, this is applicable if you are using Servlet 2.4 or above.

Hope this helps.
 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Eddy Lee Sin Ti:
You can try to use the <dispatcher> under the <filter-mapping> element to further controler how your filter is activated. Note, this is applicable if you are using Servlet 2.4 or above.

Hope this helps.


That won't do it because images also are requests.
 
Eddy Lee Sin Ti
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That won't do it because images also are requests


True. Url pattern mapping gotta be refactored then.
 
Lucas Lee
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes,you need change your URL pattern mapping to from *.* to something like *.jsp.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic