Javascript 无法在html中导入js文件

Javascript 无法在html中导入js文件,javascript,html,angularjs,eclipse,import,Javascript,Html,Angularjs,Eclipse,Import,我一直在这里寻找答案,但我找不到适合我的。我在尝试将javascript文件导入html时遇到了一个问题(我在EclipseMars2.0中编写代码)。我正在使用ApacheTiles创建模板,项目(试图)是在Angularjs中构建的。这里我附上一些代码和截图 我的html看起来像这样,在第一种情况下${contexto}值是“home” 我的项目是这样组织的 我在部署时遇到的错误是: 提前感谢 编辑我认为问题与servlet配置有关。。。如果我对web.xml中的servlet配

我一直在这里寻找答案,但我找不到适合我的。我在尝试将javascript文件导入html时遇到了一个问题(我在EclipseMars2.0中编写代码)。我正在使用ApacheTiles创建模板,项目(试图)是在Angularjs中构建的。这里我附上一些代码和截图

我的html看起来像这样,在第一种情况下${contexto}值是“home”


我的项目是这样组织的

我在部署时遇到的错误是:

提前感谢

编辑我认为问题与servlet配置有关。。。如果我对web.xml中的servlet配置进行注释,我可以访问localhost:8080/web/js/home/home-app.js文件,并且我有“Hello world”表单index.htm,但无法访问localhost:8080/web/home。另一方面,如果我不协调它们,我无法访问js文件,但我可以访问localhost:8080/web/home。这是我的web.xml,如果有帮助的话

。。。
上下文配置位置
/WEB-INF/applicationContext.xml
org.springframework.web.context.ContextLoaderListener
appServlet
org.springframework.web.servlet.DispatcherServlet
上下文配置位置
/WEB-INF/servlet/servlet-config.xml
1.
appServlet
/
WebApprotKey
webapp.web


解决方案我可以解决这个问题,将jsp中的资源定义为spring资源,而不是传统的。。。标签

根据您的web服务器,
脚本
标记试图访问不存在的文件。根据文件结构的屏幕截图,URL的
js/home/home app.js
js/home/home service.js
部分似乎是正确的,因此问题就在这之前

  • 该项目是在文档根目录中还是在其所在的子目录中
  • 如果在
    js
    之前添加斜杠,会发生什么情况

对不起,我建议您看看这个关于Dlobal的演示:

但是

  • 我认为这个全局变量在执行时存在错误,js文件没有调用.html

您忘记了
视图
directory@Ben哈罗德-那么它最终会成为一个例子?我的错误。该目录与JS文件处于同一级别。无论如何,您都希望可以从浏览器访问
脚本
标记中包含的URL。例如:
http://localhost:8080/home/js/home/home-app.js
应该可以从你的浏览器中找到。嗨,@Ben Harold,你说得对。。。我无法从localhost:8080/web/js/home/访问js文件。js
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><tiles:insertAttribute name="title" ignore="true" /></title>

        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">

        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js"></script>
        <script src="http://angular-ui.github.io/ui-router/release/angular-ui-router.js"></script>

        <script src="js/${contexto}/${contexto}-app.js"></script> 
        <script src="js/${contexto}/${contexto}-service.js"></script> 

    </head>

    <body>

            <tiles:insertAttribute name="header" />
            <tiles:insertAttribute name="body" />
            <tiles:insertAttribute name="footer" />

    </body>
</html>
   ...

    <!-- ==============Spring============= -->

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/applicationContext.xml
        </param-value>
    </context-param>

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

    <!-- Processes application requests -->
    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/servlet/servlet-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>  

    <context-param>
        <param-name>webAppRootKey</param-name>
        <param-value>webapp.web</param-value>
    </context-param>

    </web-app>