java链接jQuery文件与SpringMVC
我在链接jQuery文件时遇到了一个问题,我已经放置了。下的js文件
网络内容
--js
----开关。js
文件结构显示在。。。(http://i.imgur.com/oRzM0tP.png)
网络。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>
springdispatcherservlet。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>
但是js文件没有链接,请给我一个方向,提前谢谢
# 1 楼答案
我认为您应该放置
${pageContext.servletContext.contextPath}
,并且应该注意SpringDispatcherServlet中声明的名称(和版本)。xml必须与/js目录中的文件相同(jquery-1.6.2.js、jquery-1.11.1.js、jquery.js v.v.)正如大家所建议的,确保你有
在春天。xml
希望它能起作用
# 2 楼答案
这不是一个很好的spring方式,但我可以链接一个javascript文件,如下所示
<script type="text/javascript" src="/js/jquery-1.11.1.js" ></script>
请检查它是否也适用于您