GET angular.js文件网:: ERR_ABORTED

问题描述:

我需要你的帮助来找出我的错误在哪里。我使用springboot(后端)x Angularjs(前端)。尝试加载localhost:8080时,我得到一个GET(angular.js)文件net :: ERR_ABORTED。我的角文件也没有发现任何错误。因此,这里是我的代码:GET angular.js文件网:: ERR_ABORTED

//for the springcontroller 

@RestController 
public class EmployeeController { 

    @Autowired 
    EmployeeService es; 

    @RequestMapping(method=RequestMethod.GET,value="/employees") 
    public List<Employee> getAllEmployees(){ 
     return es.getAllEmployees(); 
    } 

    @RequestMapping(method=RequestMethod.GET,value="/employees/{name}") 
    public Employee getEmployee(@PathVariable String name){ 
     return es.getEmployee(name); 
    } 

    @RequestMapping(method=RequestMethod.POST,value="/employees") 
    public void addEmployee(@RequestBody Employee emp){ 
     es.addEmployee(emp); 
    } 

    @RequestMapping(method=RequestMethod.PUT,value="/employees/{name}") 
    public void updateEmployee(@RequestBody Employee emp,@PathVariable String name){ 
     es.updateEmployee(emp,name); 
    } 

    @RequestMapping(method=RequestMethod.DELETE,value="/employees/{name}") 
    public void deleteEmployee(@PathVariable String name){ 
     es.deleteEmployee(name); 
    } 
} 

对于我app.js:

(function(){ 
    'use strict'; 
    var app = angular.module('myApp',['ngRoute','myApp.controller']); 

    app.config(function($routeProvider) { 
     $routeProvider 
     .when('/', { 
      templateUrl: 'index.html', 
      controller: 'HomeController' 
     }); 
    }); 

})(); 

对于我HomeController.js

var module = angular.module('myApp.controller',['myApp.service']); 
module.controller('HomeController',['$scope','HomeService', 
    function($scope,HomeService){ 
     $scope.EmpData = []; 

     var onSuccess = function(response){ 
      $scope.EmpData = response.data; 
     }; 

     var onError = function(error){ 
      console.log('Error fetching data...'); 
     }; 

     function getAllEmployees(){ 
      HomeService.getAllEmployees().then(onSuccess,onError) 
     }; 
    } //end of function 

]); 

对于我HomeService.js

var module = angular.module('myApp.service',[]); 
module.service('HomeService',['$http',function($http){ 
     function doFetchEmployees(){ 
      var response = $http.get("/employees"); 
      return response; 
     }; 
     return{ 
      getAllEmployees : function(){ 
       return doFetchEmployees(); 
     } 
    }; 

    }]); 

最后是我的index.html

<html> 
<head> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 

    <script src="src/main/resources/scripts/angular.min.js"></script> 
    <script src ="src/main/resources/scripts/angular-route.min.js"></script> 
    <script src="src/main/resources/app.js"></script> 
    <script src = "src/main/resources/HomeController.js"></script> 
    <script src ="src/main/resources/HomeService.js" ></script> 
</head> 
<body ng-app="myApp" ng-controller="HomeController"> 
    <h2>Home</h2> 
    <br/> 
    <a href="#/index.html">Home</a> 
    <br/> 
    <table> 
    <thead> 
    <tr> 
     <th>Name</th> 
     <th>Email</th> 
     <th>Address</th> 
     <th>telephone</th> 
    </tr> 
    </thead> 
    <tbody ng-repeat="emp in EmpData"> 
     <tr> 
     <td>{{emp.name}}</td> 
     <td>{{emp.email}}</td> 
     <td>{{emp.address}}</td> 
     <td>{{emp.telephone}}</td> 
     </tr> 
    </tbody> 
    </table> 

    <br/> 
    <a href="http://localhost:8080/adduser.html">Create User</a> 
</body> 
</html> 

这里都是我的错误信息:

GET http://localhost:8080/src/main/resources/scripts/angular-route.min.js net::ERR_ABORTED 
localhost/:7 GET http://localhost:8080/src/main/resources/app.js net::ERR_ABORTED 
localhost/:5 GET http://localhost:8080/src/main/resources/scripts/angular.min.js net::ERR_ABORTED 
localhost/:8 GET http://localhost:8080/src/main/resources/HomeController.js net::ERR_ABORTED 
localhost/:9 GET http://localhost:8080/src/main/resources/HomeService.js net::ERR_ABORTED 
localhost/:6 GET http://localhost:8080/src/main/resources/scripts/angular-route.min.js net::ERR_ABORTED 
localhost/:7 GET http://localhost:8080/src/main/resources/app.js net::ERR_ABORTED 
localhost/:8 GET http://localhost:8080/src/main/resources/HomeController.js net::ERR_ABORTED 
localhost/:9 GET http://localhost:8080/src/main/resources/HomeService.js net::ERR_ABORTED 

我的index.html没有输出只是{{emp.names}} - >这样的。 我已经尝试将脚本标签放在身体内,但仍然一样。硬缓存重新加载&清除。仍然没有运气。 最后,当我尝试访问本地主机:8080我的eclipse控制台日志显示这3行,这也是错误的一些原因?

2017-10-18 10:31:22.115 INFO 9176 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]  : Initializing Spring FrameworkServlet 'dispatcherServlet' 
2017-10-18 10:31:22.115 INFO 9176 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet  : FrameworkServlet 'dispatcherServlet': initialization started 
2017-10-18 10:31:22.127 INFO 9176 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet  : FrameworkServlet 'dispatcherServlet': initialization completed in 12 ms 

我很难弄清楚这一点。

enter image description here

+0

请显示您的项目结构为后端和前端 – shazin

+0

我添加了项目结构的图像,你现在可以看到它吗? – LogronJ

+0

尝试将所有静态文件(css,js)放在目录'src/main/resources/static'上 –

问题是针对角度脚本的完整源路径。

我已经改变它变成这样:

<script src="angular.js""></script> 
<script src ="angular-route.min.js"></script> 
<script src="app.js"></script> 
<script src = "HomeController.js"></script> 
<script src ="HomeService.js" ></script> 

尝试添加下面一行在弹簧mvc.xml(可能是差异在您的项目名称),并改变你的位置的文件夹名称(如果它不是资源,在我的病情它的资源)

弹簧mvc.xml

<mvc:resources mapping="/resources/**" location="/resources/" cache-period="31556926"/> 

* .JSP

<script type="text/javascript" src="${ pageContext.request.contextPath }/resources/script/angular.js"></script> 

如果已经添加,请检查您是否添加了缓存周期

我有同样的问题。但我想..如果同一个网站正在其他服务器上工作,为什么不在我的服务器上..所以..我做了什么..

我试图直接访问该页面。使用URL ..

https://localhost:8080/folder/folder/script.js

https://localhost:8080/folder/folder/style.css

每当我无法访问这些文件。

然后我检查了文件夹的权限..这是700,所以我改变了对755 ..

现在。一切都运行良好:)