Lier le fichier jQuery avec Spring MVC

J'ai un problème lors de la connexion du fichier jQuery, j'ai placé le fichier .js sous

Contenu Web

–js

—– toggle.js

La structure du fichier est affichée en … ( http://i.imgur.com/oRzM0tP.png )

Fichier Web.xml

<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>FirstSpringMVCProject</display-name> <servlet> <servlet-name>spring-dispatcher</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> </servlet> <servlet-mapping> <servlet-name>spring-dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app> 

Spring-dispatcher-servlet.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/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"> <context:component-scan base-package="com.gontuseries.studentadmissioncontroller" /> <mvc:resources mapping="/css/**" location="/css/" /> <mvc:resources mapping="/js/**" location="/js/" /> <mvc:annotation-driven/> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" > <property name="prefix"> <value>/WEB-INF/</value> </property> <property name="suffix"> <value>.jsp</value> </property> </bean> 

Mais le fichier .js n'est pas relié, merci de me donner des instructions, merci d'avance !!!

Je pense que vous devriez mettre ${pageContext.servletContext.contextPath} et vous devriez remarquer que le nom (et la version) déclarer dans Spring-dispatcher-servlet.xml doit correspondre avec le fichier dans le répertoire / js (jquery-1.6.2.js, Jquery-1.11.1.js, jquery.js vv ..)

 <script type="text/javascript" src="${pageContext.servletContext.contextPath}/js/jquery-1.6.2.js"></script> 

Et comme chacun le suggère, assurez-vous que vous avez

 <mvc:resources mapping="/js/**" location="/js/" /> 

Dans Spring-dispatcher-servlet.xml

J'espère que ça marche

Il ne s'agit pas d'une très grande source, mais je pourrais lier un fichier javascript comme ci-dessous

<script type="text/javascript" src="/js/jquery-1.11.1.js" ></script>

Vérifiez si cela fonctionne aussi pour vous.