Igor  Masternoy
Igor Masternoy

Reputation: 436

Calling jsp with ajax+spring MVC

I have a problem while returning jsp from controller using ajax+spring mvc. I want to refresh a piece of the full page. In fact this is display-tag table. My controller send me this page, but the data that back to me from a controller is a jstl tags it is not html page. So browser, certainly, do not show me that page.

$(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);
        }
    });
});

My Controller Looks like this

@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>

Alert show me this code it not show me html.

Upvotes: 1

Views: 4624

Answers (1)

JB Nizet
JB Nizet

Reputation: 691735

If what you showed us is the full code of the JSP, then you simply forgot to declare the two taglibs at the top of the JSP:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="display" uri="http://displaytag.sf.net" %>

Upvotes: 1

Related Questions