1

I have a Spring MVC project i have some resources like images and pictures that is being called by the application. I am getting a 404 Not Found Error when i request the resources. E.g. I have a swf file his should be loaded with a page but it keeps giving the 404 message in firebug.

I have this file located outside the WEB-INF directory in a directory called swf. This was working previously and for some reason it stopped. Can someone assist me with the configuration details and location of where resources called by the application should be located. I am aware that files that the Spring container requests can be located inside the WEB-INF directory and all others must reside outside (i stand to be corrected on this).

File Structure:

-app
 -src
 -test
 -db
 -war
  -images
  -swf
  -WEB-INF
   -classes
   -css
   -js
   -jsp
   -lib
   -photos
   -tld
devdar
  • 5,564
  • 28
  • 100
  • 153
  • 2
    check the following link http://stackoverflow.com/questions/10734458/how-to-access-the-images-from-jsp – sasankad Jan 14 '13 at 00:56

1 Answers1

2

There's something really wrong with your file structure. You have JS and CSS under WEB-INF folder. These files will not be accessible from web. Static contents cannot be placed under WEB-INF folder.

Structure your files, like this:-

-app
    -src
    -test
    -db
    -war
        - resources
            -images
            -css
            -js
            -swf
    -WEB-INF
        -classes
        -jsp
        -lib

Add this line to your spring-servlet.xml:-

<mvc:resources location="/resources/" mapping="/resources/**" />

With this, your base URL for all static contents become /<context-root>/resources/, ex: /myapp/resources/images/test.jpg.

Further, it is possible that your application server isn't configured to serve SWF file. So, if the image files work fine but the SWF files don't work, you may want to add the following mime type to your web.xml:-

<mime-mapping>
    <extension>swf</extension>
    <mime-type>application/x-shockwave-flash</mime-type>
</mime-mapping> 

EDIT

The solution to this problem is to write a small servlet to serve SWF file.

Community
  • 1
  • 1
limc
  • 39,366
  • 20
  • 100
  • 145
  • i am getting error: Flash movie not yet registered! for the swf file and 404 Not Found console error, any thoughts. I did restructure and configure my application as you indicated. The swf file turns on my webcam (http://www.xarg.org/project/jquery-webcam-plugin/). Really need some help with this – devdar Jan 14 '13 at 01:44
  • The images are showing up fine and working however the console still shows the 404 error – devdar Jan 14 '13 at 01:45
  • Does this help? http://stackoverflow.com/questions/11085562/jquery-webcam-plugin-error-flash-movie-not-yet-registered – limc Jan 14 '13 at 01:47
  • I am not able to access any static contents using their base URL – devdar Jan 14 '13 at 01:47
  • That link doesn't help like i said i tried using the url for the static content and still it doesn't work – devdar Jan 14 '13 at 01:52
  • 1
    Are you able to hit `http://server/app/resources/swf/yourswf.swf` from the browser? Does that work? Is that the path you specified under `swffile` parameter for the webcam plugin? – limc Jan 14 '13 at 01:53
  • What application server are you running on? Tomcat? – limc Jan 14 '13 at 01:54
  • I am getting HTTP Status 404. Yes i am using TomCat 7 – devdar Jan 14 '13 at 01:55
  • 1
    See this: http://stackoverflow.com/questions/132052/servlet-for-serving-static-content . You basically need to write a small servlet to serve SWF file. I had the same problem as this in the past, and in my case, Websphere provided a servlet to do just that. Here was my post: http://stackoverflow.com/questions/4786602/allowing-audio-files-in-spring-mvc-3-0 – limc Jan 14 '13 at 02:08
  • waw these worked really great man thank you so much you should update your answer with these links. – devdar Jan 14 '13 at 02:40