4

I have the following directory structure

structure http://img853.imageshack.us/img853/7092/96816871.jpg

My CSS tries to use an image as a background

#search-text {
width: 213px;
height: 28px;
padding: 6px 0 0 7px;
border: none;
background: url(../images/img02.jpg) no-repeat left top;
color: #000000;

}

and it doesn't work while other parts of css work fine.

Firebug shows that application tries to access image by URL _http://localhost:8080/images/img02.jpg and gets 404 error

When I try to access image directly I also get this error. Also I tried _http://localhost:8080/paygate/images/img02.jpg _http://localhost:8080/paygate/resources/images/img02.jpg ...and this error doesn't stop follow me.

When I've changed my CSS file to the following

background: url(images/img02.jpg) no-repeat left top;

warning appeared in webserver log:

WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/paygate/images/img02.jpg] in DispatcherServlet with name 'appServlet'

and Firebug showed 404 error for URL _http://localhost:8080/paygate/images/img02.jpg

How should I organize my directory structure or what should I do to make my images accessible. Thank's!

P.S. I'm using springsource tc server as a webserver.

1.01pm
  • 841
  • 1
  • 12
  • 23
Greg
  • 41
  • 1
  • 1
  • 3

2 Answers2

2

According to your project structure, the .css file and images folder is in the same level, So:

background: url(images/img02.jpg) no-repeat left top;

will work.

Genzer
  • 2,921
  • 2
  • 25
  • 38
  • Nothing changed. Firebug: http://localhost:8080/paygate/images/img02.jpg 404 error and appeared warning in web server log WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/paygate/images/img01.jpg] in DispatcherServlet with name 'appServlet' – Greg May 29 '11 at 13:47
  • 1
    This message indicates that the Spring DispatcherServlet is mapped to /images/img01.jpg (through a servlet-mapping element in your web.xml). It thus tries to find a URL mapping for this path in its configuration and doesn't find one. The images shouldn't be mapped to the dispatcher servlet. – JB Nizet May 29 '11 at 14:02
2

Static resources are supposed to be served by the container's default servlet. However whenever you map any servlet on an URL pattern of / or /* in your webapp, then the default servlet will be completely overridden. You don't want to have that. Map the Spring dispatcher servlet on a more specific URL pattern, e.g. /app/* or *.html or whatever. If you don't want to have changes in the URL, then you need to put static resources in a fixed folder like /static and create a Filter which will forward the non-static resources to the Spring dispatcher servlet.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555