• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Jsp on Tomcat does not load css

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I'm developing a jsp page webapp with Eclipse and I run it on Tomcat 7.

In the jsp page I put this css tag:

<link href="../css/new_style.css" rel="stylesheet" type="text/css"/>

Also, at the beginning of the jsp page I put this:

<%@ page contentType="text/html;charset=utf-8" %>

However when I contact via browser such jsp page the css is NOT loaded and I found that the reason is
(returned by Google Chrome):

"Resource interpreted as Stylesheet but transferred with MIME type text/plain."

What should I modify? (I'm gettin crazy with this problem)
 
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check this thread and see if a filter is causing the problem.
 
alessandro panzeri
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my jsp there isn't any filter...then could it be a Tomcat issue?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Apparently stylesheets aren't served as "text/css" - make sure there are no mappings anywhere that would change that. This should be defined in conf/web.xml, and not be changed by the web.xml of your app.
 
alessandro panzeri
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In conf/web.xml I have this:

<mime-mapping>
<extension>css</extension>
<mime-type>text/css</mime-type>
</mime-mapping>

But in web.xml of the webapp I don't have anything about css...
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See the JspFaq for an entry on why using page-relative URLs for resources is almost guaranteed to cause problems like this and how to properly format resource URLs.
 
alessandro panzeri
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried what you said but I got the same results, in fact the URL of css is already correct.
The problem here is related to "MIME type" settings of css but the trouble is that I don't know if
those settings reside in the jsp code or in Tomcat configuration.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you used the browser tools to look at the response to see that content type header's value?

Regardless of whether the URL is currently working, a page-relative URL is fragile and should not be used.
 
alessandro panzeri
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

When I call the page and inspecting the response http headers I see this header:

Content-type: text/html;charset=utf-8
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The response of the page is not relevant; what's the content type on the response for the CSS resource?
 
alessandro panzeri
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when I call the css I do NOT get any Content-Type header
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That shouldn't cause any problems. In that case, the browser should correctly interpret the stylesheet according to the settings of the link element.

Are all your resources encoded as UTF-8?
 
alessandro panzeri
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

In the jsp page there is this:

<%@ page contentType="text/html;charset=utf-8" %>

So I believe yes.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That has nothing whatsoever to do with the actual encoding of the files. That directive is simply you declaring that you have created the files as UTF-8 encoded files. Whether they actually are UTF-8 or not is a completely different matter.

It's like someone saying that the sky is green when it is actually blue. Just saying it is green doesn't make it any greener.

Check the encoding of your files to see that they are actually encoded in UTF-8.
 
alessandro panzeri
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I changed the jsp files from ANSI to UTF-8 (like you said) and restarted Tomcat but the same problem persists:

"Resource interpreted as Stylesheet but transferred with MIME type text/plain."
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But, is the stylesheet loaded? Does the dev tools network tool show the CSS?
 
reply
    Bookmark Topic Watch Topic
  • New Topic