Json 数据表错误:";请求的未知参数“;

Json 数据表错误:";请求的未知参数“;,json,spring-mvc,jackson,jquery-datatables,Json,Spring Mvc,Jackson,Jquery Datatables,我是DataTables jquery插件的新手。在发现IE8在Javascript方面存在性能问题后,我决定改变使用DataTables进行服务器端处理的方式。当我的JSP加载时(我使用的是Spring3),我收到了这个错误消息: 我搜索了一下,发现导致错误消息的许多原因都归结为格式错误的JSON,因此我找到了一种从Spring3控制器函数输出JSON的方法,以查看它生成的JSON,并更改了代码,使其与网站所说的非常接近 仍然没有乐趣,仍然收到错误信息 我为DataTables找到的服务器端处

我是DataTables jquery插件的新手。在发现IE8在Javascript方面存在性能问题后,我决定改变使用DataTables进行服务器端处理的方式。当我的JSP加载时(我使用的是Spring3),我收到了这个错误消息:

我搜索了一下,发现导致错误消息的许多原因都归结为格式错误的JSON,因此我找到了一种从Spring3控制器函数输出JSON的方法,以查看它生成的JSON,并更改了代码,使其与网站所说的非常接近

仍然没有乐趣,仍然收到错误信息

我为DataTables找到的服务器端处理示例没有包含用于指定客户端使用的列的代码,因此我假设不需要它。是吗

以下是我的结果的相关部分。jsp:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >

<head>
    <title>ACME: search results in a nice DataTables.net Plugin</title>
</head>
<body>

<link rel="stylesheet" type="text/css" href="css/jquery.dataTables.css" />
<script language = "JavaScript" type = "text/javascript" src = "../nsd/js/jquery-1.7.js"></script>
<script language = "JavaScript" type = "text/javascript" src = "../nsd/js/jquery.dataTables.js"></script>

<script type="text/javascript">
$(document).ready(function() {
    $('#results_table').dataTable( {
        "bProcessing": true,
        "bServerSide": true,
        "sScrollX": "600px",
        "sServerMethod": "POST",
        "sAjaxSource": "/acme/resultstable",
    } );
} );
</script>


<form id="command" name="f" action="employee" method="post">

    <div id = "results">
        <table id = "results_table">
            <thead>           
                <tr>
                    <th>&nbsp;</th>
                    <th>ID</th>
                    <th>NO_PRINT</th>
                    <th>Full Name</th>
                    <th>Email Address</th>
                    <th>Phone Number</th>
                    <th>Organization</th>
                    <th>Organization Code</th>
                    <th>Position</th>
                    <th>Employee Type</th>
                </tr>
            </thead>
            <tbody>           
            </tbody>
        </table>

    </body>
</html>
{
  "sEcho" : 1,
  "iTotalRecords" : 1,
  "iTotalDisplayRecords" : 1,
  "aaData" : [ {
    "person_id" : "888888",
    "ID" : "999999",
    "no_print" : "&nbsp;",
    "fullname" : "Obama, Willard",
    "email_address" : "<a href = \"mailto:barry@whitehouse.gov\">barry@whitehouse.gov</a>",
    "current_phone_number" : "303-867-5309",
    "title" : "&nbsp;",
    "office" : "&nbsp;",
    "position" : "Contractor",
    "empl_code" : "CONT"
  } ]
}

ACME:在一个漂亮的DataTables.net插件中搜索结果
$(文档).ready(函数(){
$('结果表')。数据表({
“bProcessing”:正确,
“bServerSide”:正确,
“sScrollX”:“600px”,
“sServerMethod”:“POST”,
“sAjaxSource”:“/acme/resultstable”,
} );
} );
身份证件
不打印
全名
电子邮件地址
电话号码
组织机构
组织机构代码
位置
员工类型
这是我发送给它的JSON响应:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >

<head>
    <title>ACME: search results in a nice DataTables.net Plugin</title>
</head>
<body>

<link rel="stylesheet" type="text/css" href="css/jquery.dataTables.css" />
<script language = "JavaScript" type = "text/javascript" src = "../nsd/js/jquery-1.7.js"></script>
<script language = "JavaScript" type = "text/javascript" src = "../nsd/js/jquery.dataTables.js"></script>

<script type="text/javascript">
$(document).ready(function() {
    $('#results_table').dataTable( {
        "bProcessing": true,
        "bServerSide": true,
        "sScrollX": "600px",
        "sServerMethod": "POST",
        "sAjaxSource": "/acme/resultstable",
    } );
} );
</script>


<form id="command" name="f" action="employee" method="post">

    <div id = "results">
        <table id = "results_table">
            <thead>           
                <tr>
                    <th>&nbsp;</th>
                    <th>ID</th>
                    <th>NO_PRINT</th>
                    <th>Full Name</th>
                    <th>Email Address</th>
                    <th>Phone Number</th>
                    <th>Organization</th>
                    <th>Organization Code</th>
                    <th>Position</th>
                    <th>Employee Type</th>
                </tr>
            </thead>
            <tbody>           
            </tbody>
        </table>

    </body>
</html>
{
  "sEcho" : 1,
  "iTotalRecords" : 1,
  "iTotalDisplayRecords" : 1,
  "aaData" : [ {
    "person_id" : "888888",
    "ID" : "999999",
    "no_print" : "&nbsp;",
    "fullname" : "Obama, Willard",
    "email_address" : "<a href = \"mailto:barry@whitehouse.gov\">barry@whitehouse.gov</a>",
    "current_phone_number" : "303-867-5309",
    "title" : "&nbsp;",
    "office" : "&nbsp;",
    "position" : "Contractor",
    "empl_code" : "CONT"
  } ]
}
{
"sEcho":1,,
“iTotalRecords”:1,
“iTotalDisplayRecords”:1,
“aaData”:[{
“人员id”:“8888888”,
“ID”:“999999”,
“无打印”:“,
“全名”:“奥巴马,威拉德”,
“电子邮件地址”:“,
“当前电话号码”:“303-867-5309”,
“名称”:“名称”,
“办事处”:“,
“职位”:“承包商”,
“雇员代码”:“续”
} ]
}
这里是我的Spring控制器函数,我使用它通过Jackson发送JSON响应。这包括输出JSON的代码,以便我可以看到它的样子。它输出到stdout的JSON和我发送回DataTables的JSON会不同吗

@RequestMapping(value = "/resultstable", method = RequestMethod.POST)
public @ResponseBody LinkedHashMap resultstable(ModelMap model,                 
                                                HttpSession session,
                                                @RequestParam (required=true) int sEcho,   
                                                @RequestParam (required=true) int iDisplayStart,   
                                                @RequestParam (required=true) int iDisplayLength,    
                                                @RequestParam (required=true) int iColumns,
                                                @RequestParam (required=true) int iSortCol_0, 
                                                @RequestParam (required=false)String sSortDir_0,
                                                @RequestParam (required=true) String sSearch ) {

    /*
    **********************************************************************
    **  These come from the DataTables.net Jquery plugin on results.jsp
    **********************************************************************
    **  sEcho,          -  just send it back, used by DataTables for synching
    **  iDisplayStart   -  index of the record to start with, ie 3 for the 3rd of 100 records
    **  iDisplayLength  -  number of records to send back starting with iDisplayStart  
    **  iColumns        -  number of columns to be displayed in the table
    **  iSortCol_0      -  the number of thee column to be sorted on
    **  sSortDir_0      -  direction of sorting: asc or desc
    **  sSearch         -  from the search box, filter results further on this term 
    ********************************************************************** 
    */

    String nextView                   = "results";
    String usertype                   = (String)session.getAttribute("usertype");
    Search search                     = new Search(usertype);
    List<LinkedHashMap> records       = null;
    String results                    = null;
    int number_of_records             = (Integer)session.getAttribute("number_of_records_found");
    ResultsView rv                    = new ResultsView();
    ResultsScreenTableHolder rstrh    = null;
    SearchScreenDataHolder ssdh2      = (SearchScreenDataHolder)session.getAttribute("search_screen_data_holder");
    ObjectMapper mapper               = new ObjectMapper();

    logger.debug("started");

    logger.debug("sEcho,         == " + sEcho         );
    logger.debug("iDisplayStart  == " + iDisplayStart  );
    logger.debug("iDisplayLength == " + iDisplayLength );
    logger.debug("iColumns       == " + iColumns       );
    logger.debug("iSortCol_0     == " + iSortCol_0     );
    logger.debug("sSortDir_0     == " + sSortDir_0     );
    logger.debug("sSearch        == " + sSearch        );


    try {
        records = search.searchForAnEmployee(ssdh2,usertype,sSearch,"asc",
                                             iSortCol_0,iDisplayStart, 
                                             iDisplayLength);    


        LinkedHashMap lhm= new java.util.LinkedHashMap();
        lhm.put("sEcho", sEcho);
        lhm.put("iTotalRecords",number_of_records);
        lhm.put("iTotalDisplayRecords",9);
        lhm.put("aaData",records);

        // convert user object to json string, and save to a file
        mapper.writeValue(new File("c:\\Downloads\\rstrh.json.txt"), lhm);

        // display to console
        logger.debug("My JSON: " + mapper.defaultPrettyPrintingWriter().writeValueAsString(lhm));

    }
    catch (Exception e) {
        logger.debug("\n",e);
    }

    return lhm;       

}// end function 
@RequestMapping(value=“/resultstable”,method=RequestMethod.POST)
public@ResponseBody LinkedHashMap结果表(ModelMap模型,
HttpSession,
@RequestParam(required=true)int sEcho,
@RequestParam(required=true)intIDisplayStart,
@RequestParam(required=true)int-iDisplayLength,
@RequestParam(required=true)int-iColumns,
@RequestParam(必需=true)int iSortCol_0,
@RequestParam(必需=false)字符串sSortDir_0,
@RequestParam(必需=true)字符串(搜索){
/*
**********************************************************************
**这些来自results.jsp上的DataTables.net Jquery插件
**********************************************************************
**sEcho,-只需将其发送回,由DataTables用于同步
**iDisplayStart—要开始的记录的索引,即100条记录中的第3条记录的索引为3
**iDisplayLength—从iDisplayStart开始发送回的记录数
**iColumns—表中要显示的列数
**iSortCol_0-要排序的列数
**sSortDir_0-分拣方向:asc或desc
**sSearch-从搜索框中,进一步筛选此术语的结果
********************************************************************** 
*/
字符串nextView=“results”;
String usertype=(String)session.getAttribute(“usertype”);
搜索=新搜索(用户类型);
列表记录=空;
字符串结果=null;
int number_of_records=(整数)session.getAttribute(“number_of_records_found”);
ResultsView rv=新的ResultsView();
ResultsScreenTableHolder rstrh=null;
SearchScreenDataHolder ssdh2=(SearchScreenDataHolder)session.getAttribute(“搜索屏幕数据持有人”);
ObjectMapper mapper=新的ObjectMapper();
调试(“已启动”);
debug(“sEcho,==”+sEcho);
debug(“iDisplayStart==”+iDisplayStart);
debug(“iDisplayLength==”+iDisplayLength);
debug(“iColumns==”+iColumns);
debug(“iSortCol_0==”+iSortCol_0);
logger.debug(“sSortDir_0==”+sSortDir_0);
debug(“sSearch==”+sSearch);
试一试{
records=search.searchForAnEmployee(ssdh2,用户类型,sSearch,“asc”,
iSortCol_0,iDisplayStart,
i显示长度);
LinkedHashMap lhm=new java.util.LinkedHashMap();
lhm.put(“sEcho”,sEcho);
lhm.put(“iTotalRecords”,记录的数量);
lhm.put(“iTotalDisplayRecords”,9);
lhm.put(“aaData”,记录);
//将用户对象转换为json字符串,并保存到文件
writeValue(新文件(“c:\\Downloads\\rstrh.json.txt”),lhm;
//显示到控制台
debug(“MyJSON:+mapper.defaultPrettyPrintingWriter().writeValueAsString(lhm));
}
捕获(例外e){
aoColumns: [
  { "mData": "Field1", sDefaultContent: "n/a" },
  { "mData": "Field2", sDefaultContent: "" }
]
"aaData" : [ 
  [
   "person_id" : "888888",
   "ID" : "999999",
  ],
  [
   "person_id" : "8888889",
   "ID" : "9999990",
  ]
]