This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
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.
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.
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 ]
Joined: Jan 15, 2003
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.
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!
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 ]
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.