File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Spring and the fly likes Spring 3.2.0.M2 : Using Static Resources Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring 3.2.0.M2 : Using Static Resources" Watch "Spring 3.2.0.M2 : Using Static Resources" New topic

Spring 3.2.0.M2 : Using Static Resources

Ackshat Sharma

Joined: Sep 03, 2011
Posts: 22
Hello Everyone , I started learning spring framework a month back reading "Spring in Action 3" and Online tutorials, I want to use static resources i.e css and js files.
I am using Eclipse JUNO where if you choose a new project as 'Dynamic Web Project' that's the hierarchy of folders I am talking here.
I have used

the 'resources' folder(placed in parallel to 'WEB-INF' inside 'WebContent' ) containing 'js' , 'css' folder which further contains .js and .css files respectively, these jQuery and Css are used in home.jsp.
I have a mapping as '/app/home' in a controller 'AppController' for a jsp page home.jsp placed in WebContent-->WEB-INF-->view-->jsp-->home.jsp.
another mapping as ' /app/home/userhome' in same controller using same ModelAndMap return type method returning a 'new ModelAndMap("home")' instance.
the problem is the former case works fine but later does not, the browser on viewing the source for the generated html content gives error 404(not found) when the js and css links are clicked.

What I concluded is spring mvc is having some problem with the context path , since it is the difference in mapping which let the dispatcher looking at two different location for the same mapped resource.

here is dispatcher-servlet.xml

web.xml is as

AppController as

here is the snippet of the home.jsp

Can anyone help and tell is there a way we can map and get our static content used without have to worry about context path every time we put a new mapping heirarchy(since the mapping is logical and helps to make a logical hierarchy for a portal or any web service ).

Thanks a lot sparing your time for this.
Bill Gorder

Joined: Mar 07, 2010
Posts: 1682

Try the curl tag. See here:

[How To Ask Questions][Read before you PM me]
Ackshat Sharma

Joined: Sep 03, 2011
Posts: 22
Thanks Bill, It worked when I used

So it works when we specify context attribute too.
I agree. Here's the link:
subject: Spring 3.2.0.M2 : Using Static Resources
It's not a secret anymore!