Java 在Spring MVC中尝试显示YUI数据表时出现数据错误

Java 在Spring MVC中尝试显示YUI数据表时出现数据错误,java,javascript,spring,yui,Java,Javascript,Spring,Yui,我正在做一个关于Spring和YUI数据表的项目 我使用controller返回JSON字符串,在视图中,我将使用JSON字符串作为数据源来生成数据表。但不知何故,数据表显示“数据错误” 以下是我的控制器的代码: @请求映射(value=“/report”) public model和view getViolationReport(长违规次数){ ComplLog origViolation=null; //HashMap logdetailsmap=新HashMap(); Map Map=ne

我正在做一个关于Spring和YUI数据表的项目

我使用controller返回JSON字符串,在视图中,我将使用JSON字符串作为数据源来生成数据表。但不知何故,数据表显示“数据错误”

以下是我的控制器的代码:

@请求映射(value=“/report”) public model和view getViolationReport(长违规次数){

ComplLog origViolation=null;
//HashMap logdetailsmap=新HashMap();
Map Map=newhashmap();
map.put(“col1”、“value1”);
map.put(“col2”、“value2”);
map.put(“col3”、“value3”);
map.put(“col4”、“value4”);
map.put(“col5”、“value5”);
列表=新的ArrayList();
列表。添加(地图);
ModelAndView mav=新ModelAndView();
mav.addObject(“详细列表”,列表);
mav.setViewName(“GetViolationReport”);//将模型返回到GetViolationReport.jsp
返回mav;
}
这是我的index.jsp文件:

<% response.sendRedirect("/app/ViolationReportService.app"); %>

以下是我的视图GetViolationReport.jsp:

<body class="yui-skin-sam" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">
<div id="scroller" class="scrollPane">
    <c:out value = "${detailList}" />    
</div>
<div id="basic"></div> 
</body>
<script type="text/javascript">
YAHOO.util.Event.addListener(window, "load", function() {
YAHOO.example.Basic = function() {
    var myColumnDefs = [
        {key:"col1", sortable:true, resizeable:true},
        {key:"col2", sortable:true, resizeable:true},
        {key:"col3", sortable:true, resizeable:true},
        {key:"col4", sortable:true, resizeable:true},
        {key:"col5", sortable:true, resizeable:true}

    ];
 var myDataSource = new YAHOO.util.XHRDataSource("app/violationreport/report");
    myDataSource.responseType = YAHOO.util.XHRDataSource.TYPE_JSON;
    myDataSource.responseSchema = {
        metaFields : {
            totalRecords : "detailmap.totalRecordsFound",
            recordsReturned : "detailmap.totalRecordsFound",
            invocationStatus : "invocationStatus",
            startIndex : 0,
            executionStatusMessage : "executionStatusMessage"
        },
        resultsList : "detailList",
        fields : [ "col1","col2","col3","col4","col5" ] 
    }
var myDataTable = new YAHOO.widget.DataTable("basic",
            myColumnDefs, myDataSource, {initialLoad: true, caption:"DataTable Caption"});

    return {
        oDS: myDataSource,
        oDT: myDataTable
    };
 }();
});
</script>

YAHOO.util.Event.addListener(窗口,“加载”,函数(){
YAHOO.example.Basic=函数(){
var myColumnDefs=[
{key:“col1”,可排序:true,可调整大小:true},
{key:“col2”,可排序:true,可调整大小:true},
{key:“col3”,可排序:true,可调整大小:true},
{key:“col4”,可排序:true,可调整大小:true},
{key:“col5”,可排序:true,可调整大小:true}
];
var myDataSource=newyahoo.util.XHRDataSource(“app/violationreport/report”);
myDataSource.responseType=YAHOO.util.XHRDataSource.TYPE_JSON;
myDataSource.responseSchema={
元字段:{
totalRecords:“detailmap.totalRecordsFound”,
记录返回:“detailmap.totalRecordsFound”,
调用状态:“调用状态”,
startIndex:0,
executionStatusMessage:“executionStatusMessage”
},
结果列表:“详细列表”,
字段:[“col1”、“col2”、“col3”、“col4”、“col5”]
}
var myDataTable=newyahoo.widget.DataTable(“基本”,
myColumnDefs,myDataSource,{initialLoad:true,标题:“DataTable caption”});
返回{
oDS:myDataSource,
oDT:myDataTable
};
}();
});
actoolkit-config.xml如下所示:

<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
    <property name="favorParameter" value="true" /> 
    <property name="mediaTypes">
        <map>
            <entry key="json" value="application/json" /> 
            <entry key="html" value="text/html" /> 
            <entry key="plain" value="text/plain" /> 
            <entry key="octet" value="application/octet-stream" /> 
        </map>
    </property>
    <property name="viewResolvers">
        <list>
            <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
            <bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
                <property name="viewClass"
                    value="org.springframework.web.servlet.view.JstlView" />
                <property name="prefix" value="/WEB-INF/jsp/" />
                <property name="suffix" value=".jsp" />
            </bean>
        </list>
    </property>

    <property name="defaultViews">
        <list>
            <bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />                   
        </list>
    </property>
    <property name="defaultContentType" value="application/json" /> 
</bean>

控制台中没有错误,但当我转到应该生成数据表的url时,它显示了一个包含我定义的列的数据表,但内容显示为“数据错误”


有人能帮我一下吗?

数据实际上是什么样子的?浏览器接收到的是什么?我不理解您的非JavaScript代码,即使我理解了,有时代码中也会出现一些错误,服务器会抛出一条客户端无法解析的错误消息。因此,在浏览器中打开调试器,看看浏览器实际得到了什么

现在我可以获取要显示的数据,但是我将requestmapping更改为@requestmapping(value=“/report/{invalition_num}”),因此如果我希望数据表显示从数据库获取的数据,我必须先转到http://******/app/violationreport/report/123124获取JSON数据,然后转到******/violationreportservice/调用数据表以使其显示。。。有什么方法可以让我转到http://*****/app/violationreport/report/123124,然后直接将数据显示在数据表中?我不知道你在说什么。这可以是YUI问题或Spring问题。到目前为止,我们还不知道。决定它的一个方法是显示浏览器实际得到的内容。如果这是正确的,那么这是一个YUI问题,如果它是错误的,那么这是一个Spring问题。我最终让它工作起来,实际上是因为我在数据源中写了一个错误的url。我把它改成“http://....../**.json“然后我得到要显示的数据表。
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
    <property name="favorParameter" value="true" /> 
    <property name="mediaTypes">
        <map>
            <entry key="json" value="application/json" /> 
            <entry key="html" value="text/html" /> 
            <entry key="plain" value="text/plain" /> 
            <entry key="octet" value="application/octet-stream" /> 
        </map>
    </property>
    <property name="viewResolvers">
        <list>
            <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
            <bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
                <property name="viewClass"
                    value="org.springframework.web.servlet.view.JstlView" />
                <property name="prefix" value="/WEB-INF/jsp/" />
                <property name="suffix" value=".jsp" />
            </bean>
        </list>
    </property>

    <property name="defaultViews">
        <list>
            <bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />                   
        </list>
    </property>
    <property name="defaultContentType" value="application/json" /> 
</bean>