Meaningless Drivel is fun!*
The moose likes JSP and the fly likes CSS was ignored due to mime type mismatch Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "CSS was ignored due to mime type mismatch" Watch "CSS was ignored due to mime type mismatch" New topic
Author

CSS was ignored due to mime type mismatch

Likos Anthropous
Greenhorn

Joined: May 06, 2013
Posts: 17
Dear colleagues,

I’m seeking help to try to solve a problem that is desperating me!!!

I have a JSP where I include the following CSS and JavaScript files like this:



It seems that everything must be OK, but the JSP appears on the navigator, I realize that the CSS and JavaScript files are ignored…

In the IE Web Console I get the error message “"CSS was ignored due to mime type mismatch" …

I can’t understand the reason of this message. As you can see, I state rel="stylesheet" type="text/css" .

It must be something very stupid, but so far I was not able to find the root of this error.

Hope someone could give me a helping hand…

Thank you very much in advance for your attention.

Kind regards.

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30324
    
150

Could your server be sending back a http header with each of the requests? Maybe it defaults to a specific MIME type?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Likos Anthropous
Greenhorn

Joined: May 06, 2013
Posts: 17
Jeanne Boyarsky wrote:Could your server be sending back a http header with each of the requests? Maybe it defaults to a specific MIME type?


Dear Jeanne,

Thank you very much for your quick response. I'm using Apache Tomcat 7.0.34.0 and I did not have this situation in any of my previous experiences.

Sorry but, as I'm not very much experienced yet in Web Programming, I don't know how to check the header sent back by the server :(...

Thanks again.

Regards.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

IE is notorious for misleading messages. I'd open the page in Chrome and use its network tools.

Also, I'd advise against using page-relative URLs to refer to the resources. See the JspFaq for more info.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Likos Anthropous
Greenhorn

Joined: May 06, 2013
Posts: 17
Bear Bibeault wrote:IE is notorious for misleading messages. I'd open the page in Chrome and use its network tools.

Also, I'd advise against using page-relative URLs to refer to the resources. See the JspFaq for more info.


Thanks Bear,

I changed the resources path using ${pageContext.request.contextPath}, now remains like this:



But now the messages I get in the Google Chrome Console are the following:

Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost:8084/Shambala/Estilos/lksMenuSkin3.css". localhost/:16
Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost:8084/Shambala/Estilos/styleCSS3Menu.css". localhost/:17
Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost:8084/Shambala/Estilos/validacion.css". localhost/:18
Resource interpreted as Script but transferred with MIME type text/html: "http://localhost:8084/Shambala/JS/jquery-1.4.2.min.js". localhost/:20
Resource interpreted as Script but transferred with MIME type text/html: "http://localhost:8084/Shambala/JS/jquery.lksMenu.js". localhost/:20
Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost:8084/Shambala/Estilos/style.css".


I think we'e getting closer...

Thanks.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

What is serving these resources?
Likos Anthropous
Greenhorn

Joined: May 06, 2013
Posts: 17
Bear Bibeault wrote:What is serving these resources?


I'm using Apache Tomcat 7.0.34.0. The JSP page is loaded from a servlet through the following code:



Hope it helps.

Thanks.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Do you perhaps have a filter which specifies "text/html" as the MIME type, and which is being applied to your CSS and JS files?
Likos Anthropous
Greenhorn

Joined: May 06, 2013
Posts: 17
Paul Clapham wrote:Do you perhaps have a filter which specifies "text/html" as the MIME type, and which is being applied to your CSS and JS files?


Thanks for your answer Paul.

I do have a filter but I belive has nothing to do with the MIME type. Anyway I post the code below, just in case you note something odd...



Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I don't see any special handling for ".css" so I suppose if the filter does handle those files, it would forward to your "controlador" parameter. Perhaps that applies the MIME type?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

Why is your filter even mapped for any static resource? You shouldn't even have images, scripts or stylesheets going through the filter.
Likos Anthropous
Greenhorn

Joined: May 06, 2013
Posts: 17
Bear Bibeault wrote:Why is your filter even mapped for any static resource? You shouldn't even have images, scripts or stylesheets going through the filter.


Well, this is some kind of "inherited code"..., but now it seems that I found where the mistake was...

As you can see there is an if sentence that checks the file extension and in case of .gif and .jpg, it allows the file to go through... I also included here .css and .js files and now these resources are loaded...

Is that what you meant by mapping static resources?

I don't know if this is the best way to proceed, maybe not, but at least the problem is solved...


Thank you Jeanne, Paul & Bear for all our support.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

I mean that the filter should be mapped in the deployment descriptor such that it never even gets called for resources that it doesn't care about. Checking for images and such in the filter is, as you have discovered, fragile and a poor way to go about it.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I have to admit, the last time I wrote a web application I had code just like that in my filter. (Which is probably why I could point out the problem here.) That's because I couldn't figure out how to configure the filter to be triggered for "everything except" a certain list of patterns. I'm sure I wouldn't be hijacking the thread if I asked for an example of how to do that.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

Admittedly it's a lot easier when using a Front Controller as there's just one url pattern to worry about. This is what I always do. Otherwise, you need to map a bunch of stuff and the deployment descriptor is kinda messy.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: CSS was ignored due to mime type mismatch