【发布时间】:2017-03-30 00:58:52
【问题描述】:
大家好,我是 Spring MVC 的新手,所以我对这个框架知之甚少。我要做的就是用休眠查询过滤的项目刷新视图中的 div,该查询可以正确打印到标准输出。
出于某种原因,我不知道我得到了 500;当我尝试通过 ajax 获取请求时出现内部服务器错误。 我更改了控制器中的返回类型,我最初的想法是使用带有可选参数的默认索引控制器。
查看:
<div id="itemListContainer">
<c:if test="${!empty items}">
<c:forEach items="${items}" var="item">
<c:url value="/showImage.htm" var="url">
<c:param name="id" value="${item.id}" />
</c:url>
<div id="${item.id}" class="col-lg-2 col-md-3 col-xs-6 thumb">
<img class="img-responsive" src="${url}" alt="${item.name}">
</div>
<input id="name_${item.id}" type="hidden" value="${item.name}">
<input id="name_${item.id}" type="hidden" value="${item.review}">
</c:forEach>
</c:if>
<c:if test="${!empty itemList}">
<h1>Nothing found</h1>
</c:if>
</div>
JS 文件
function filterItems(value) {
$("#itemListContainer").empty();
$.ajax({
method: "GET",
//dataType: "json",
url: "filterItems.htm",
data: {
type: value
},
success: function (data) {
if (data) {
$("#itemListContainer").html(data);
} else {
console.log(xhr.responseText);
alert("failure");
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("Status: " + textStatus); alert("Error: " + errorThrown);
}
});
}
控制器:
@RequestMapping(value = "/filterItems", method = RequestMethod.GET)
public @ResponseBody List<Item> filterItems(@RequestParam(value = "type", required = false) String type) {
List<Item> items = new ArrayList<Item>();
try {
items = itemDao.getItems(type);
} catch (Exception e) {
e.printStackTrace();
}
return items;
}
任何帮助将不胜感激。提前致谢!!
【问题讨论】:
-
请包含相关的堆栈跟踪。
-
“服务器遇到一个内部错误,阻止它完成这个请求”。从 Eclipse 控制台中我也能看到。我很乐意粘贴 catalina.out 日志条目,但我不知道在 Mac OSX 中哪里可以找到这些条目
标签: ajax spring hibernate spring-mvc