Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/408.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将jQuery文件链接到SpringMVC_Java_Javascript_Jquery_Spring_Spring Mvc - Fatal编程技术网

Java 将jQuery文件链接到SpringMVC

Java 将jQuery文件链接到SpringMVC,java,javascript,jquery,spring,spring-mvc,Java,Javascript,Jquery,Spring,Spring Mvc,我在链接jQuery文件时遇到了一个问题,我将.js文件放在了 网络内容 --js -----toggle.js 文件结构显示在。。。() 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"

我在链接jQuery文件时遇到了一个问题,我将.js文件放在了

网络内容

--js

-----toggle.js

文件结构显示在。。。()

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>

FirstSpringMVC项目
春季调度员
org.springframework.web.servlet.DispatcherServlet
春季调度员
/

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>

/WEB-INF/
.jsp

但是.js文件没有链接,请给我一个方向,提前谢谢

这不是一种很好的spring方式,但我可以链接一个javascript文件,如下所示


请检查它是否也适用于您

我认为您应该把
${pageContext.servletContext.contextPath}
放进去,并且您应该注意到Spring-dispatcher-servlet.xml中声明的名称(和版本)必须与/js目录中的文件相同(jquery-1.6.2.js,jquery-1.11.1.js,jquery.js v.v.)


正如大家所建议的,确保你有

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

在Spring-dispatcher-servlet.xml中


希望它能起作用

你能展示一下你的web.xml文件吗?因为迟来的回复,你已经编辑了这个问题,谢谢你的帮助……我想你只需要在你的spring-dispatcher-servlet.xml文件中添加一个
。这将本质上把静态内容的处理委托给容器。另外删除
谢谢@BijuKunjummen,它仍然没有链接到.js文件,我不知道我哪里出错了。感谢您的指导-任何错误,控制台上的任何内容,请尝试让日志级别进行调试,以查看可能出现的错误。Spring应该在这个日志级别显示足够的信息难以置信!成功了,非常感谢你@Tung Vo,
<mvc:resources mapping="/js/**" location="/js/" />