aspose file tools*
The moose likes Servlets and the fly likes Forward/Include getting picked up by servlet mapping Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Forward/Include getting picked up by servlet mapping" Watch "Forward/Include getting picked up by servlet mapping" New topic
Author

Forward/Include getting picked up by servlet mapping

Ben Williams
Greenhorn

Joined: Jan 15, 2003
Posts: 17
Hi,

I'm hoping somebody can help with a problem I'm facing. I'm trying to provide a mechanism whereby URLs with the *.html extension are mapped to a servlet, and then the servlet either forwards directly to an HTML file of the same name, or intervenes, such as for authentication purposes.

The problem I'm facing is that the flow of the include/forward process (e.g. JSP <jsp:include page="<%=pageName%>"/>, dispatcher.forward(...), etc.) goes through the server filter and servlet mechanism. Specifically, the forward to the HTML page gets mapped to the same servlet the external request did, and the request loops back again.

Is there a way to prevent forwards/includes from going through the servlet/filter mechanism? I've tried adding <dispatcher>REQUEST</dispatcher> to servlet-mapping, which doesn't help (I'm not sure it's a valid child attribute, anyway). I really don't want to rename any files, as I'm attempting to work with the designers on a large project and need to drop HTML files into the application without altering URLs.

Using Tomcat 5.0.27

I'll greatly appreciate any solutions or tips!

Cheers,
Ben


Ben Williams - SCJP2, SCWCD
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

You mean setting <dispatcher> in <filter-mapping> does not help ?
Setting it to REQUEST, or not setting it at all is the same.


[My Blog]
All roads lead to JavaRanch
Ben Williams
Greenhorn

Joined: Jan 15, 2003
Posts: 17
Originally posted by Satou kurinosuke:
You mean setting <dispatcher> in <filter-mapping> does not help ?
Setting it to REQUEST, or not setting it at all is the same.


Hi. I saw that attribute in <filter-mapping> and wishfully hoped it also applied to <servlet-mapping>, so that's where I tried it. I'm not using any filters for this project, so the problem only lies with the servlet.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

There is no such <dispatcher> tag for <servlet-mapping>
You might consider using filters for such purposes.
[ January 04, 2006: Message edited by: Satou kurinosuke ]
Ben Williams
Greenhorn

Joined: Jan 15, 2003
Posts: 17
Originally posted by Satou kurinosuke:
There is no such <dispatcher> tag for <servlet-mapping>
You might consider using filters for such purposes.


I figured that, after trying it I wonder why there isn't a corresponding dispatcher tag for servlet-mapping? Good idea with the filters. I've put my original servlet functionality under a filter mapped to requests only. The problem is still that the forward/include gets mapped to a servlet, and whether the servlet does anything or not, it still blocks loading of the HTML file.

There must be a straightforward way of spitting out the HTML file without either looping through the servlet/filter process or using File IO.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

I don't understand the problem then.
I thought you may do :

1. Configure a filter, mapped to all HTML files
2. Make the filter class, and do whatever you want in the doFilter() method
3. That's all. The HTML file will then be displayed.

This page might help you
Ben Williams
Greenhorn

Joined: Jan 15, 2003
Posts: 17
Originally posted by Satou kurinosuke:
I don't understand the problem then.
I thought you may do :

1. Configure a filter, mapped to all HTML files
2. Make the filter class, and do whatever you want in the doFilter() method
3. That's all. The HTML file will then be displayed.

This page might help you


Excellent! I've now got it working, thanks to your first point; I wasn't aware that filters could be mapped to URL patterns, but instead thought they could only be mapped to servlets. Thanks a lot for your help!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61218
    
  66

Originally posted by Ben Williams:
I'm trying to provide a mechanism whereby URLs with the *.html extension are mapped to a servlet


DON'T DO IT!

We tried doding something "clever" like this at a previous job and it was a complete disaster! Turns out there are some "helpful" servers out there (most notably, AOL) that assume that all URLs that end in .html are static in nature and they "helpfully" cache them. The results was that data from one customer was being returned to another out of these caches that you have no control over.

Never ever ever, and did I mention ever, map what looks like a static resource to a dynamic one. That way lies pain and grief.
[ January 05, 2006: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ben Williams
Greenhorn

Joined: Jan 15, 2003
Posts: 17
Originally posted by Bear Bibeault:


DON'T DO IT!

Oh, the dreaded caching bug bites again! Thanks for your advice Bear. Do you think that intermediate servers on the Internet cache resources even if you set the headers to no-cache? Are the servers/routers smart enough to know not to cache jsp/asp/php/do files?

In the past I've had issues getting browsers to not cache resources, including those with jsp and do extensions, and often resort to appending a unique request ID to every URL.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61218
    
  66

Originally posted by Ben Williams:

Do you think that intermediate servers on the Internet cache resources even if you set the headers to no-cache?


They did then, 'cause we set no-cache on all the pages. I'm not sure if the situation has changed, but I wouldn't risk it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Forward/Include getting picked up by servlet mapping