我正在构建一个应用程序,它在客户端使用 AngularJS,在服务器端使用 java。在主页上,我有几个餐厅类别的链接,单击这些链接都会导致部分restorani.html。这样我就可以知道哪个餐厅类别被点击了,我已经在 URL 中添加了一个 id,所以它看起来像这样:
<a href="#/restorani/1">Chinese food</a> <br />
<a href = "#/restorani/2">Italian food</a>
Restorani.html 需要显示点击类别中的餐厅。 我的 Controller 如下所示:
app.controller('RestoranController', function($routeParams, $scope,
RestoranService){
function init(){
RestoranService.getById($routeParams.id).then(function(response){
$scope.jela = response.data;
});
}
init();
});
这是我发送获取请求的服务:
app.factory('RestoranService', function($http){
var factory = {};
factory.getById = function(id){
return $http.get('/WebProjekat/rest/restorani/getById/' + id);
}
return factory;
}); 这是我的服务器端代码:
@GET
@Path("/getById/{id}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public ArrayList<Artikli> getById(@PathParam("id") String id){
int idNum = Integer.parseInt(id);
ArrayList<Restoran> listaRestorana =
(ArrayList<Restoran>)ctx.getAttribute("restorani");
if(listaRestorana == null) {
listaRestorana = readAllRestorane();
ctx.setAttribute("restorani", listaRestorana);
}
Restoran r = getRestoranById(listaRestorana, idNum);
return r.getListaJela();
}
对于某些人来说,我未知的原因,我不断收到此错误:
获取http://localhost:8008/WebProjekat/rest/restorani/getById/1 500(内部 服务器错误)。
如果有人告诉我错误在哪里,我将非常感激。如果这是一些微不足道的错误,我很抱歉,但我找不到,并且我已经投入了很多时间。
最佳答案
因为此错误是“500(内部服务器错误)”。您的应用程序可能在 getById() 方法中出现异常。
要调试此方法:- 在 getById() 中添加调试点并在 Debug模式下运行服务器。并在服务器控制台中查找错误或 stackTrace。
关于java - 使用java从服务器端的URL中提取参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52146837/