views:

348

answers:

3

I have a home page home.html inside a war file named "webapp-1.0.war". When the browser requests "http://domain/myapp" I want the home.html served up, but I want the browswer address bar to continue to display "http://domain/myapp". I DO NOT want "http://domain/myapp/home.html" in the address bar.

So I put this into the web.xml:

<welcome-file-list>
  <welcome-file>home.html</welcome-file>
</welcome-file-list>

And I added a jboss-web.xml with the following:

<jboss-web>
  <context-root>myapp</context-root>
</jboss-web>

This almost works. When the browser requests "http://domain/myapp" the home.html is sent, but the mime type is application/octet-stream instead of text/html, and this makes Firefox think it is a file download.

+2  A: 

This is not the default behaviour.

Mime types are normally definied in web.xml. In case of Tomcat and clones, the appserver-default mime types are definied in /conf/web.xml.

This can however be overridden by custom mime mapping entries in the webapp's /WEB-INF/web.xml or by a HttpServletResponse#setContentType() in a servlet or filter in the request-response chain. I can imagine that there is some sort of poor filter listening on /* which incorrectly sniffs and sets the content type based on the request URL. See if something similar exist in your webapp.

BalusC
Aha, good to know. My webapp is based on Restlet 2.0m5, and I do indeed have it listening to /*. I am new to Restlet so I'll dig in there some more. Thanks for helping me eliminate one possibility! I'll post back when I know more.
Kevin Pauli
Oh, you should have mentioned that you're using Restlet. This is maybe just a configuration matter. I have never used it, so I can't give a detailed answer, but the answer of ZZ Coder look like a good one. Try it.
BalusC
A: 

It does indeed appear to be the default behavior of Restlet. After thinking about it some more, I suppose I like the behavior. Thinking RESTfully, I suppose the web app as a whole (which is what is implied by the root url) is not really the resource my browser is interested in retrieving. The browser is really interested in an html representation of the "home" resource, which is a part of the web app. So I guess I'll leave it. But I'll go ahead upvote you, BalusC for taking the time to answer for me.

Kevin Pauli
+1  A: 

"octet-stream" is the default mime-type in Restlet. The "html" is defined in the default mapping. Looks like you have your own MetaDataService. You can add extension mappings like this,

getMetadataService().addExtension("html", MediaType.TEXT_HTML, true);
ZZ Coder
Thanks! Yeah I saw all those imperative API calls to set that stuff... I was hoping to find an easy way to do it declaratively with the Spring extension but no luck so far. But that is another question for another day, and like I said in my answer, I really don't mind the default behavior after thinking about it some more.
Kevin Pauli