CSS
and JS
are not being render in my application-
This is my Dispatcher.xml
-
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config />
<context:component-scan base-package="com.ttnd.springdemo.controller" />
<mvc:resources location="/resources/" mapping="/resources/**" />
<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
and below is the page in which i am using css/js
-
I tried this by various way,some of them are-
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/application.css">
<script src="js/application.js"></script>
<script src="js/bootstrap.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.min.js"></script>
</head>
or-
<link rel="stylesheet" type="text/css" href="<spring:url value='resources/css/application.css' />" />
<script src="<spring:url value='resources/js/application.js' />"></script>
<script src="<spring:url value='resources/js/jquery.min.js' />"></script>
I had a similar problem with my css and the way in which I fixed it was....
If you want to test it to see if your css is being read, you can try to access the css file through your browser, by using the following url or something similar to http://localhost:8080/spring/resources/css/main.css. This should show your css file in your browser
I also had a similar problem. Fixed it by:-
webapp/resources
directory.<mvc:resources location="/resources/" mapping="/resources/**" />
.Hope it works for you as well.
EDIT
I include my JS/CSS Like
I included the static files using
for css
for js
and include following tags in the jsp
hope it helps