• Post Reply Bookmark Topic Watch Topic
  • New Topic

Jsp on Tomcat does not load css  RSS feed

 
alessandro panzeri
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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)
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
In my jsp there isn't any filter...then could it be a Tomcat issue?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • 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
  • 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...
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
when I call the css I do NOT get any Content-Type header
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But, is the stylesheet loaded? Does the dev tools network tool show the CSS?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!