File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Multiple requests made on each single page load Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Multiple requests made on each single page load" Watch "Multiple requests made on each single page load" New topic
Author

Multiple requests made on each single page load

David Rocks
Ranch Hand

Joined: Apr 24, 2001
Posts: 162
Hi,

I have a filter infront of my JSPs and this seems to be getting called multiple times when I hit a JSP.

I have tracked this down to images in my page with standard img HTML elements causing the requests. It seems that each image will cause another hit on the filter.

The problem is that the filter does a bit of DB work and that is going to kill my server if traffic builds up.

I realise that my filter pattern could be changed but really it has to do many different types of real request so I do want it to be /*

Does anyone have any clues as to how this could be stopped.

TIA
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61756
    
  67

The filter will match whatever you express as its pattern. Using "/*" it will match anything.

Don't do that.

You'll need to figure out an alternate filter mapping scheme.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
David Rocks
Ranch Hand

Joined: Apr 24, 2001
Posts: 162
So a IMG tag will create a new request just to go from one JSP file in the directory and pick up an gif file ?

Even if I do not use a filter is that not a high load for a simple task.

Struts and hibernate will both tell you to use /* in their filters.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Images are separate requests--not much you can do about that.

You *can*, however, decide to not process the request in the filter if it's an image. S2 uses /* as the filter mapping because we serve static content from specific directories--if the request doesn't match the action pattern or the magic prefix the filter stops processing and moves on.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61756
    
  67

Images, style sheets, JavaScript files, video and so on are all separate requests.

I'd use a better mapping strategy (unless you are using Struts or whatever -- then use their recommendation), or follow David's advice of writing the filter to determine if it needs to pay attention to a request or not (painful in my opinion).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multiple requests made on each single page load