0

我的请求处理程序看起来像这样

@ResponseBody
    @RequestMapping(value = "/jsonTable", method = RequestMethod.GET)
    public ModelAndView populateJsonTable(@ModelAttribute("model") Person model) {
       DataTables<Person> dt = new DataTables<Person>();
       Map<String, Object> result = new HashMap<String, Object>();
       Person person = new Person();
       List<Person> personList = person.findMatches(ctxt.getSession(), 1);
       dt.setEntityData(personList);
       dt.setiTotalDisplayRecords(5);
       result.put("personList", JsonUtil.toJson(dt));
       return new ModelAndView("TeamViewer", result);
    }

Jsp页面是这样的

<head>
    <meta http-equiv="Content-Type" content="application/json; charset=windows-1252">
    <title>JSP Page</title>
    <c:set var="baseURL" value="${pageContext.request.contextPath}"/>
    <link href="${baseURL}/css/jquery-ui-1.8.16.custom.css" rel="stylesheet" type="text/css" />
    <link href="${baseURL}/css/jtable_green.css" rel="stylesheet" type="text/css" />

    <script src="${baseURL}/js/jquery-1.6.min.js" type="text/javascript"></script>
    <script src="${baseURL}/js/jquery-ui-1.8.16.custom.min.js" type="text/javascript"></script>

    <script src="${baseURL}/js/jquery.jtable.js" type="text/javascript"></script>
    <script src="${baseURL}/js/json2.js" type="text/javascript"></script>
</head>

When i hit the ("http://localhost:8080/sample/view/jsonTable") url the its show the following error. 

错误:此请求标识的资源只能生成具有根据请求“接受”标头()不可接受的特征的响应。

任何人都可以说出这段代码有什么问题。

我想用 Json 制作一个数据网格。所以我的想法是从数据库中获取数据作为 Java 模型,然后将其转换为 json 形式。然后将其提供给浏览器。为此,我粘贴了更多 TeamViewer。jsp。或者,如果您可以在其他链接中将 java 数据转换为 json 形式,然后将其呈现为 jsp。然后请分享。

提前致谢

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html" >
        <title>JSP Page</title>
        <c:set var="baseURL" value="${pageContext.request.contextPath}"/>
        <link href="${baseURL}/css/jquery-ui-1.8.16.custom.css" rel="stylesheet" type="text/css" />
        <link href="${baseURL}/css/jtable_green.css" rel="stylesheet" type="text/css" />

        <script src="${baseURL}/js/jquery-1.6.min.js" type="text/javascript"></script>
        <script src="${baseURL}/js/jquery-ui-1.8.16.custom.min.js" type="text/javascript"></script>

        <script src="${baseURL}/js/jquery.jtable.js" type="text/javascript"></script>
        <script src="${baseURL}/js/json2.js" type="text/javascript"></script>
    </head>
    <body>
        <script>

        var jqxhr = $.getJSON( "example.json", function() {
            console.log( "success" );
            })
            .done(function() {
            console.log( "second success" );
            })
            .fail(function() {
            console.log( "error" );
            })
            .always(function() {
            console.log( "complete" );
            });

            $(document).ready(function() {      

                //setup hellothe jtable that will display the results
                $('#ExpenseTableContainer').jtable({
                    title: 'Table of Expenses',
                    selecting: true, //Enable selecting 
                    paging: true, //Enable paging
                    pageSize: 10, //Set page size (default: 10)
                    sorting: true, //Enable sorting
                    actions: {
                        listAction: '${baseURL}/view/jsontable',
//                         createAction: '${baseURL}/datatable/addExpense',
//                         updateAction: '${baseURL}/datatable/updateExpense',
//                         deleteAction: '${baseURL}/datatable/deleteExpense'
                    },
                    fields: {
                        Id: {
                            key: true,
                            list: true,
                            create: false,
                            edit: false
                        },

                        Name: {
                            key: true,
                            list: true,
                            create: false,
                            edit: false
                        },

                        FirstName: {
                            title : 'First Name',
                            width : 30%''
                        },
                        Date: {
                            title: 'Date',
                            width: '30%'
                        },
                        Amount: {
                            title: 'Amount',
                            width: '15%'
                        },
                        CategoryId: {
                            title: 'Category',
                            options: '${baseURL}/datatable/categories'
                        },
                        SubcategoryId: {
                            title: 'Sub Category',
                            dependsOn: 'CategoryId',
                            options: function (data) {
                                if (data.source == 'list') {
                                    //Return url of all countries for optimization.
                                    //This method is called for each row on the table and jTable caches options based on this url.
                                    return '${baseURL}datatable/subcategories?categoryId=0';
                                }
                                return '${baseURL}/datatable/subcategories?categoryId=' + data.dependedValues.CategoryId;
                            },
                            list: false
                        },        
                        Description: {
                            title: 'Description',
                            width: '25%'
                        }
                    },
                    rowInserted: function (event, data) {
                        //if (data.record.Name.indexOf('Andrew') >= 0) {
                            $('#ExpenseTableContainer').jtable('selectRows', data.row);
                            console.log("records inserted");
                            //$('#PeopleTableContainer').jtable('load');
                        //}
                    },
                    //Register to selectionChanged event to hanlde events                                     
                    recordAdded: function(event, data){
                        //after record insertion, reload the records
                        $('#ExpenseTableContainer').jtable('load');
                    },
                    recordUpdated: function(event, data){
                        //after record updation, reload the records
                        $('#ExpenseTableContainer').jtable('load');
                    }
                });
                $('#ExpenseTableContainer').jtable('load');              

            });    
        </script>
4

1 回答 1

0

我不是 100% 确定您要做什么,但 @ResponseBody 似乎是问题所在。这个注解告诉 Spring 序列化方法返回的对象并发送给客户端。如果您要返回 ModelAndView,您可能希望将名为 TeamViewer 的渲染视图发送到客户端。简而言之,删除@ResponseBody。

于 2013-10-22T13:26:10.803 回答