无法在jsp中找到js文件 [英] Unable to locate js file in jsp

查看:149
本文介绍了无法在jsp中找到js文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了针对此问题发布的所有问题。但我没有找到解决方案。

I went through all the SO question posted for this problem. But I didn't find solution.

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

I created project Spring MVC project using IntelliJ Idea and I am using Tomcat 7.42 My project structure is as shown in picture.

我的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>

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>

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

Now my problem is I am unable to get js file located and also ${pageContext.request.contextPath} is coming as blank.

同样的原因是什么?

推荐答案

你的mvc-dispatcher-servlet.xml中是否有资源映射用于提供静态资源,可能就像下面一样?

Do you have resource mappings in your mvc-dispatcher-servlet.xml in for serving up static resources, maybe like following?

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

这篇关于无法在jsp中找到js文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆