1
使用ajax + spring mvc从控制器返回jsp时出现问题。我想刷新整页的一部分。实际上这是显示标签表。我的控制器发给我这个页面,但是从控制器返回给我的数据是一个jstl标签,它不是html页面。所以,浏览器当然不会让我看到那个页面。使用ajax + spring MVC调用jsp MVC
$(document).ready(function() {
alert("asdfads");
//$('#content').load('<c:url value="/pages/new.jsp"/>');
$.ajax({
url : '/shop/getCartProducts/ajax/',
type : 'GET',
async: false,
data : {},
success : function(data) {
$('#content').html(data);
alert(data);
},
error: function (jqXHR, textStatus, errorThrown) {
alert(jqXHR + " : " + textStatus + " : " + errorThrown);
}
});
});
我Controller
貌似这个
@RequestMapping(value = "/getCartProducts/ajax/", method = RequestMethod.GET)
String ajaxGetProdCart(HttpServletRequest request, Model model) {
LOG.error("We are in the controller");
PaginatedListImpl<Product> paginatedList = new PaginatedListImpl<Product>(request);
productService.getProductsFromCart(paginatedList, null, 100);
model.addAttribute("paginatedList", paginatedList);
return "cartProduct";
}
cartProduct.jsp
<display:table class="table" id="product" name="paginatedList" defaultsort="1" requestURI="/shop/cart/" excludedParams="*" export="false">
<display:column>
<a href='<c:url value="/cart/remove/"/>'> <img
src='<c:url value = "/resources/images/forbidden.png"/>'>
</a>
</display:column>
<display:column sortable="false" sortProperty="name" title="Product"
maxLength="55">
<c:url var="prodUrl" value="/product/${product.product_id}/" />
<a href='<c:out value="${prodUrl}"/>'> <c:out
value="${product.name}" />
</a>
</display:column>
<display:column property="price" paramId="price" sortable="false"
title="Price" href="#" />
<display:column property="descr" sortable="true" paramName="descr"
title="Description" maxLength="250" sortName="descr" /></display:table>
警报告诉我这段代码岂不告诉我的HTML。
我是否需要添加任何具体的视图解析器来获得它在ajax调用的成功回调处理程序中。我配置了内部视图解析器。 – HKumar