0

I am new to Spring MVC. for loading resources I have use < mvc:resources mapping="/design/**" location="/design/" />. Although this worked well, now it is not. I cannot understand the problem. Can anyone help me?

Here is my spring-dispatcher-servlet.xml. My resource(design) folder is in the WebContent and it has sub folders called css, js and images.

< 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"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/data/mongo
http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd">
<context:component-scan base-package="controller"/> 

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix">
        <value>/</value>
    </property>
    <property name="suffix">
        <value>.jsp</value>
    </property>
</bean> 

<bean id="viewResolverhtml" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix">
        <value>/</value>
    </property>
    <property name="suffix">
        <value>.html</value>
    </property>
</bean> 

<bean id="mongo" class="org.springframework.data.mongodb.core.MongoFactoryBean">
    <property name="host" value="localhost"/>
</bean>

<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
    <constructor-arg name="mongo" ref="mongo"/>
    <constructor-arg name="dabaseName" ref="testdb"/>
</bean>

<mongo:repositories base-package="model"/>

<mvc:view-controller path="/" view-name="index"/>
<mvc:resources mapping="/design/**" location="/design/" />

<mvc:annotation-driven/>

and this is how I load resources in index.jsp

<link rel="stylesheet" href="design/css/reset.css" type="text/css" media="screen">
<link rel="stylesheet" href="design/css/style.css" type="text/css" media="screen">
<link rel="stylesheet" href="design/css/grid.css" type="text/css" media="screen">
<script src="design/js/jquery-1.6.3.min.js" type="text/javascript"></script>
<script src="design/js/cufon-yui.js" type="text/javascript"></script>
<script src="design/js/cufon-replace.js" type="text/javascript"></script>
<script src="design/js/Kozuka_Gothic_Pro_OpenType_300.font.js" type="text/javascript"></script>
<script src="design/js/Kozuka_Gothic_Pro_OpenType_500.font.js"  type="text/javascript"></script>
<script src="design/js/FF-cash.js" type="text/javascript"></script>
<script type="text/javascript" src="design/js/jquery.easing.1.3.js"></script>
<script type="text/javascript" src="design/js/tms-0.3.js"></script>
<script type="text/javascript" src="design/js/tms_presets.js"></script>
<script src="design/js/jcarousellite_1.0.1.js" type="text/javascript"></script>

1 Answer 1

2

Try any of the below :

With JSTL tag c:url

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<link href="<c:url value="/design/css/reset.css" />" rel="stylesheet">

With spring:url

<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<spring:url value="/design/css/reset.css" var="reset" />

without any tags

<link href="${pageContext.request.contextPath}/design/css/reset.css" rel="stylesheet"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.