1
大家好我是新來的Spring MVC,所以我對這個框架沒有什麼想法。我想要做的就是在我的視圖中刷新一個div,並使用通過hibernate查詢進行過濾的項目,該項目可以正確打印到標準輸出。Spring MVC中ajax GET請求的內部服務器錯誤
由於某種原因,我不知道我得到一個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;
}
任何幫助將不勝感激。提前致謝!!
請包括相關的堆棧跟蹤。 – Bnrdo
「服務器遇到內部錯誤,導致無法完成此請求」。沒有例外,我可以從eclipse控制檯看到。我很樂意粘貼catalina.out日誌條目,但我不知道在Mac OSX中找到那些內容 –