• 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

Problems with Spring - how can i load .js .css or even .jpg files ?

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

I'm new to spring but not new to MVC. I'm mostly a PHP developer working with Zend Framework. Spring seems a bit different to me that's why I need your help.

It seems that every time I try to call a file (.js/.css/.jpg etc.) located on a public folder under WEB-INF I get 404 error. I'm guessing spring is redirecting everything to the dispatcher. I checked my .xml config files and there's nothing there to that says to redirect everything other than the .html requests.

I'm I missing something here ?
Thanks
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not Spring related really.

"a public folder under WEB-INF"

WEB-INF folder isn't "public" you can't just go access a file directly in that directory. That is not defined by Spring.

So what do you really mean when you say you are trying to access the file. Is it through a jsp page? Or are you trying a direct URL with something like "www.mysite.com/WEB-INF/mypicture.jpg". In the last case you can't do anywhere.

Mark
 
kokos kokouin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Mark,

Well, I'm trying to access http://domain/js/file.js

the 'js' directory is under WEB-INF. There is also a 'jsp' directory there. I tried having the .js file under both 'jsp' and under 'WEB-INF'. I still cant call it though. I get a 404 page not found.

I tried with this structure:

WEB-INF
---> jsp
---> js/file.js


and with this one:

WEB-INF
---> jsp/js/file.js

Note that I tried all the possible combination. Even those that make no sense.
http://domain/js/file.js
http://domain/jsp/js/file.js
http://domain/file.js
// These make no sense but I tried them
http://domain/WEB-INF/js/file.js
http://domain/WEB-INF/jsp/js/file.js
http://domain/WEB-INF/file.js


Any ideas why? This happens only when I use Spring. I tried with no framework and everything is ok.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Again, and I could be wrong. I am wrong all the time.

But I thought you put files in WEB-INF so that no one can access them directly. That those image files would be protected from someone trying to get them with something like...

http://domain/js/file.js
http://domain/jsp/js/file.js
http://domain/file.js
// These make no sense but I tried them
http://domain/WEB-INF/js/file.js
http://domain/WEB-INF/jsp/js/file.js
http://domain/WEB-INF/file.js

Mark
 
kokos kokouin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Mark,

no..I want them to be accessible. It just happens to be that Spring does something so I cannot access them!
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by kokos kokouin:


no..I want them to be accessible.



What I mean is that you can want whatever you want, but the Servlet spec is written that that directory is protected. That is why you put files in WEB-INF because they aren't accessible directly.

https://coderanch.com/t/357149/Servlets/java/WEB-INF-directory

The browser will never be able to access files in the WEB-INF directory directly, ever.

Mark
[ November 17, 2008: Message edited by: Mark Spritzler ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The JSPs under WEB-INF aren't being accessed directly. If you think about it, you'll realize that must be so, since a JSP is Java code has to actually be compiled to a servlet before being executed. Your web app is just set up in such a way that files in WEB-INF/jsp are mapped to /*.jsp URLs. Mark is quite right here -- by definition, the container will not serve files directly from /WEB-INF.

Instead, make your js directory next to WEB-INF -- i.e.,


/ROOT
------js/
------images/
----- WEB-INF/
-------------jsp/
 
kokos kokouin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok guys, that solved it. Thanks for your time and support!
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey,man.how did you solve the problem.i get the same problem and moving the js files out of the WEB-INF file also makes no sense.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic