Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.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
Javascript 在jsp中找不到js文件_Javascript_Jsp_Spring Mvc_Intellij Idea_Tomcat7 - Fatal编程技术网

Javascript 在jsp中找不到js文件

Javascript 在jsp中找不到js文件,javascript,jsp,spring-mvc,intellij-idea,tomcat7,Javascript,Jsp,Spring Mvc,Intellij Idea,Tomcat7,我浏览了所有关于这个问题的帖子。但我没有找到解决办法 我使用IntelliJ Idea创建了project Spring MVC项目,我使用的是Tomcat 7.42 我的项目结构如图所示 我的JSP代码 <html> <head> <script src='/js/index.js' type="text/javascript"/> </head> <body> <h1>${message}

我浏览了所有关于这个问题的帖子。但我没有找到解决办法

我使用IntelliJ Idea创建了project Spring MVC项目,我使用的是Tomcat 7.42 我的项目结构如图所示

我的JSP代码

<html>
<head>

<script src='/js/index.js' type="text/javascript"/>
</head>
<body>
     <h1>${message}
          ${pageContext.request.contextPath}
          ${pageContext.request.contextPath}
     </h1>

     <form:form action="/personDetails"  commandName="command">
     <p><form:errors path="*" cssClass="error"/></p>
         Age :<form:input path="age" cssErrorClass="myErrorClass"></form:input><br>
         Name:<form:input path="name"></form:input><br>
         City:<form:input path="city"></form:input><br>
         <input type="submit" value="Save">
      </form:form>

    </body>
    </html>

${message}

${pageContext.request.contextPath}
${pageContext.request.contextPath}

年龄:
名称:
城市:
web.xml

   <servlet>
    <servlet-name>mvc-dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>mvc-dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

mvc调度器
org.springframework.web.servlet.DispatcherServlet
1.
mvc调度器
/
org.springframework.web.context.ContextLoaderListener
index.jsp

现在我的问题是我无法找到js文件,而且
${pageContext.request.contextPath}
是空的

同样的原因是什么


中的mvc-dispatcher-servlet.xml中是否有用于提供静态资源的资源映射,可能类似于以下内容

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


您是否在tomcat根目录下运行应用程序?您用来查看该页面的URL是什么?另外,尝试将
添加到JSP的顶部。我正在使用IDE运行应用程序,我的JSP非常好,只是为了缩短我在上述代码中没有添加的代码。我删除并更新了代码以避免混淆您是否使用上下文路径查看页面?页面URL是什么${pageContext.request.contextPath}为空,我的url为空,因此您将应用程序作为根tomcat应用程序运行-因此
contextPath
应为空。看,工作不好。从运行的应用程序可能会出现问题IDE@ShoaibChikate然后需要将
src
属性更改为
${pageContext.request.contextPath}/js/index.js
@ShoaibChikate打开浏览器的网络终端,并检查浏览器为获取javascript资源而发出的请求。返回的响应代码是什么?确保它发送请求的路径是正确的。如果不是,则相应地更改它。