tags:

views:

59

answers:

2

I am writing a java servlet (struts/JSP etc). I am trying to style a progress bar using CSS in a JSP page but get this error when using chrome's developer tools:

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

<%@ include file="../include/css/default.css" %>

And in the CSS file:

background:url(../images/bg_bar.gif) no-repeat 0 0;

Could anyone explain why this is and show how I can use this CSS in my page?

A: 

My guess is that you get an error page instead of the image. Try typing full path to the image in your browser and see if it works. That is: http://domain/app/include/images/bg_bar.gif

If you get an error - then your problem is that your images are not accessible to the public.

Max
That works fine. I can see the images.
Alex
Ok, try to check if chrome is loading the image from the same path you did manually. If it uses same path - try checking response headers coming when you load image manually, check for 'Content-type' part.
Max
Ok, chrome is looking here: http://localhost:8080/images/bg_bar.gif and I loaded it from here http://localhost:8080/GraphBuilder/include/images/bg_bar.gif
Alex
It's missed the context and the folder which includes the images. Does this mean that I've got the include folder in the wrong place in my project?
Alex
Added new comment with proper answer.
Max
+1  A: 

Ahh... I got where is your problem. You are including the css with @include, so it inserts the whole css file into your html code.

The result will look like this:

localhost:8080/GraphBuilder/yourpage.htm

<html>
...
<style>
.myId {
background:url(../images/bg_bar.gif) no-repeat 0 0;
}
</style>
...

Now, looking at the address of the page, where do you think will it try to find the image? Exactly, in localhost:8080/GraphBuilder/../images/bg_bar.gif -> localhost:8080/images/bg_bar.gif.

You have 2 options to solve it:

  1. Instead of @include, use simple <style type="text/css" src="include/css/default.css"/>. This will make it look for css in the path localhost:8080/GraphBuilder/include/css/default.css. And css will look for image in localhost:8080/GraphBuilder/include/css/../images/bg_bar.gif -> localhost:8080/GraphBuilder/include/css/images/bg_bar.gif.
  2. Leave everything as it is, but change the path in css file to 'include/images/bg_bar.gif'. However this solution is worse than the first one, as including css in html file sucks.
Max
This has indeed fixed the problem. Thank you very much.
Alex
No problem. Please accept the answer then (the V sign near votes up and down).
Max