| Author |
Why is my Filter called for every image, included jsp and the main jsp?
|
Dan Bizman
Ranch Hand
Joined: Feb 25, 2003
Posts: 387
|
|
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
Joined: Jan 10, 2002
Posts: 56178
|
|
|
You probably have a URL mapping for the filter that is too broad.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56178
|
|
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
Joined: Feb 25, 2003
Posts: 387
|
|
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
Joined: Jan 10, 2002
Posts: 56178
|
|
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
Joined: Oct 06, 2005
Posts: 135
|
|
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.
|
SCJP, SCWCD, SCJWS, IBM 700,IBM 701, IBM 704, IBM 705, CA Clarity Technical<br /> <br /><a href="http://eddyleesinti.blogspot.com" target="_blank" rel="nofollow">http://eddyleesinti.blogspot.com</a>
|
 |
Dan Bizman
Ranch Hand
Joined: Feb 25, 2003
Posts: 387
|
|
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
Joined: Oct 06, 2005
Posts: 135
|
|
That won't do it because images also are requests
True. Url pattern mapping gotta be refactored then.
|
 |
Lucas Lee
Ranch Hand
Joined: Oct 02, 2006
Posts: 53
|
|
|
Yes,you need change your URL pattern mapping to from *.* to something like *.jsp.
|
 |
 |
|
|
subject: Why is my Filter called for every image, included jsp and the main jsp?
|
|
|