1

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.

1 Answer 1

1

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" %>
Sign up to request clarification or add additional context in comments.

1 Comment

Do I need to add any specific view resolver to get it inside success callback handler at ajax call. I have internal view resolver configured.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.