Spring Mvc Css Js Files

Where to place images/CSS in spring-mvc app? It is generally preferred to hide the.css/.js files from direct public access by placing them into the main/java. Here is how to add javascript/static files to the Spring MVC web project *if you are looking for job click here mvc:resources mapping='/resources.

I am new to Spring mvc. I want to add css and js files in jsp. It's a spring mvc framework. This is my spring-dispatcher-servlet.xml code SpringDemo is my project name folder.

I keep my file in SpringDemo/WebContent/resources/css and in the same location i keep my js file also SpringDemo/WebContent/resources/js Below code is jsp file called RegistrationForm.jsp.

I would put things in a /resources directory rather than /, This is a little more specific on where you static resources are located and it is also a fairly standard practice at this point. See this blog for another possible project directory structure,: Do note if you choose this one that images and styles are not under WEB-INF that will cause issues. Changing what you have a now to this might make a little more sense and is fairly common: /src/main/resources/css /src/main/resources/js /src/main/resources/images In any event the annotation that does the magic is the one you have here: This configures a handler for static resources. In this case, requests for /resources/** are mapped to files inside the / directory. Mini Windows Xp Live Cd Iso here. Icom R8500 Serial Numbers. Looking at you JSP and your directory structure I think you need to change it to this: ' rel='stylesheet' type='text/css' />'>I am not sure why you are putting.js and images under the css directory though, seems a bit confusing to me.

If you go to the src/main/resources/css etc. Approach I mentioned above change your resource mapping to the following: mvc:resources mapping='/resources/**' location='/resources/' />Then access it like this: ' rel='stylesheet' type='text/css' /. Hi Thank you for your suggesiton.

It is still failed with 405: HTTP Status 405 - Request method 'GET' not supported I have changed resources path as you suggested: src/main/resources/img/ src/main/resources/tcal.css src/main/resources/tcal.js then changed link to: ' rel='stylesheet' type='text/css' />'>in my addDeliveries.jsp file. Here is the site access path: click the button 'Add Delivery'. The 5th Horseman Pdf.

Noticed that the popup page 'addDelivery.jsp' display as normal html without any css and js. I 'd expect the field 'Delivery Date' shown a js calendar for a user to pick a date, but currently there is nothing applied to this field. Well you said you changed your resource path to src/main/resources/img/ src/main/resources/tcal.css src/main/resources/tcal.js as I suggested. What I actually suggested is: src/main/resources/css/tcal.css src/main/resources/js/tcal.js Did you also change your mvc:resources tag as I suggested to mvc:resources mapping='/resources/**' location='/resources/' />If you did then you are still not accessing them correctly. You said you used ' rel='stylesheet' type='text/css' />'>Using what you posted above (without the additional js folder) it should be '>You can find an example on the mvc showcase project One other thing in your web.xml do you have the dispatcher mapped to /?

See More On StackoverflowSpring Mvc Css Js Files