关于 esayui表格获取数据报错No result defined for action *** and result input

前台

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'userusermanager.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" type="text/css"
    href="<%=path%>/jquery-easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
    href="<%=path%>/jquery-easyui/themes/icon.css">
<link rel="stylesheet" type="text/css"
    href="<%=path%>/jquery-easyui/themes/color.css">
<link rel="stylesheet" type="text/css"
    href="<%=path%>/jquery-easyui/demo.css">
<script type="text/javascript"
    src="<%=path%>/jquery-easyui/jquery.min.js"></script>
<script type="text/javascript"
    src="<%=path%>/jquery-easyui/jquery.easyui.min.js"></script>


</head>
<style type="text/css">
#fm {
    margin: 0;
    padding: 10px 30px;
}

.ftitle {
    font-size: 14px;
    font-weight: bold;
    padding: 5px 0;
    margin-bottom: 10px;
    border-bottom: 1px solid #ccc;
}

.fitem {
    margin-bottom: 5px;
}

.fitem label {
    display: inline-block;
    width: 80px;
}

.fitem input {
    width: 160px;
}
</style>
<script type="text/javascript">
    var url;
    function editUser() {
        var row = $('#dg').datagrid('getSelected');
        if (row) {
            $('#dlg').dialog('open').dialog('center').dialog('setTitle',
                    '修改合法用户');
            $("#userAccount").combobox('readonly', true);
            $('#fm').form('load', row);
        } else {
            $.messager.alert('错误', '请选择一条用户记录', 'error');
        }
    }

    function updateUser() {
        $('#fm').form('submit', {

            url : 'update_useruser',
            onSubmit : function() {
                return $(this).form('validate');
            },
            success : function(result) {
                var result = eval('(' + result + ')');
                if (result.flag == "failed") {
                    $.messager.show({
                        title : '错误',
                        msg : '更新用户信息失败'
                    });
                } else {
                    $('#dlg').dialog('close'); // close the dialog
                    $('#dg').datagrid('reload'); // reload the user data
                }
            }
        });
    }
    function destroyUser() {
        var row = $('#dg').datagrid('getSelected');
        if (row) {
            $.messager.confirm('确认', '确定删除该条用户信息吗?', function(r) {
                if (r) {
                    $.post('destroy_useruser', {
                        userAccount : row.userAccount
                    }, function(result) {
                        if (result.flag == "success") {
                            $('#dg').datagrid('reload'); // reload the user data
                        } else {
                            $.messager.show({ // show error message
                                title : '错误',
                                msg : '删除用户信息失败'
                            });
                        }
                    }, 'json');
                }
            });
        } else {
            $.messager.alert('错误', '请选择一条用户记录', 'error');
        }
    }

        /*     function getData(){
            var rows = [];
            for(var i=1; i<=800; i++){
                
                rows.push({
                    userAccount: 'userAccount'+i,
                    userName: 'UN',
                    userPasswd: 'Name '+i,
                    userQuestion: 'AA',
                    userAnswer: 'HH',
                    userIsadmin: 'OO'
                });
            }
            return rows;
        } */
        
        function pagerFilter(data){
            if (typeof data.length == 'number' && typeof data.splice == 'function'){    // is array
                data = {
                    total: data.length,
                    rows: data
                }
            }
            var dg = $(this);
            var opts = dg.datagrid('options');
            var pager = dg.datagrid('getPager');
            pager.pagination({
                onSelectPage:function(pageNum, pageSize){
                    opts.pageNumber = pageNum;
                    opts.pageSize = pageSize;
                    pager.pagination('refresh',{
                        pageNumber:pageNum,
                        pageSize:pageSize
                    });
                    dg.datagrid('loadData',data);
                }
            });
            if (!data.originalRows){
                data.originalRows = (data.rows);
            }
            var start = (opts.pageNumber-1)*parseInt(opts.pageSize);
            var end = start + parseInt(opts.pageSize);
            data.rows = (data.originalRows.slice(start, end));
            return data;
        }
        
        $(function(){
            $('#dg').datagrid({loadFilter:pagerFilter}).datagrid('loadData', getData());
        });
    </script>
<body>
    <h2>注册用户管理</h2>


    <table id="dg" title="注册用户信息" class="easyui-datagrid"
        style="width:750px;height:400px"
        data-options="rownumbers:true,
                      toolbar:'#toolbar',
                      url:'getalluserinfo',
                      pageSize:10,
                      singleSelect:true,
                    pagination:true,
                     <!--  fitColumns:true, -->
                      method:'post'">
        <thead>
            <tr>
                <th field="userAccount" width="120">用户帐号</th>
                <th field="userAnswer" width="120">答案</th>
                <th field="userIsadmin" width="120">是否管理员</th>
                <th field="userName" width="120">用户姓名</th>
                <th field="userPasswd" width="120">密码</th>
                <th field="userQuestion" width="120">问题</th>
                
                
            </tr>
        </thead>
    </table>
    <div id="toolbar">
        <a href="javascript:void(0)" class="easyui-linkbutton"
            iconCls="icon-edit" plain="true" οnclick="editUser()">修改用户</a> <a
            href="javascript:void(0)" class="easyui-linkbutton"
            iconCls="icon-remove" plain="true" οnclick="destroyUser()">删除用户</a>
    </div>

    <div id="dlg" class="easyui-dialog"
        style="width:400px;height:280px;padding:10px 20px" closed="true"
        buttons="#dlg-buttons">
        <div class="ftitle">用户信息</div>
        <form id="fm" method="post" novalidate>
            <div class="fitem">
                <label>用户帐号:</label> <input name="userAccount"
                    class="easyui-textbox" id="userAccount" required="true">
            </div>
            <div class="fitem">
                <label>用户姓名:</label> <input name="userName" class="easyui-textbox"
                    required="true">
            </div>
        </form>
    </div>
    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton c6"
            iconCls="icon-ok" οnclick="updateUser()" style="width:90px">保存</a> <a
            href="javascript:void(0)" class="easyui-linkbutton"
            iconCls="icon-cancel" οnclick="javascript:$('#dlg').dialog('close')"
            style="width:90px">取消</a>
    </div>

    

</body>
</html>

xml配置

<action name="getalluserinfo" class="com.yusys.action.UserManageAction" method="getAllregisterUserInfo">
            <result type="json">
                 <param name="contentType">text/html</param>
            </result>
            
        </action>

java代码


package com.test.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.yusys.bean.User;
import com.yusys.service.UserService;
@SuppressWarnings("serial")
@Controller
// 将action交给spring来管理
@Scope("prototype")
public class UserManageAction extends BaseAction{
    @Resource
    UserService userService;
    private List<User> rows;
    private int total;
    public List<User> getRows() {
        return rows;
    }
    public void setRows(List<User> rows) {
        this.rows = rows;
    }
    public int getTotal() {
        return total;
    }
    public void setTotal(int total) {
        this.total = total;
    }
    /**
     * 获取所有用户信息
     * @return
     */
    public String getAllregisterUserInfo(){
        rows = userService.list();
        total = rows.size();
        return "success";
    }

}
访问action返回数据报错

No result defined for action com.test.action.UserManageAction and result input

单独访问acion名,得到

{"allUserInfo":"success","rows":[{"userAccount":"a","userAnswer":null,"userIsadmin":null,"userName":null,"userPasswd":null,"userQuestion":null},{"userAccount":"aa","userAnswer":null,"userIsadmin":null,"userName":null,"userPasswd":null,"userQuestion":null},{"userAccount":"admin","userAnswer":"北京","userIsadmin":"Y","userName":"管理员","userPasswd":"admin","userQuestion":"00"},{"userAccount":"b","userAnswer":null,"userIsadmin":null,"userName":null,"userPasswd":null,"userQuestion":null},{"userAccount":"bb","userAnswer":null,"userIsadmin":null,"userName":null,"userPasswd":null,"userQuestion":null},{"userAccount":"bbb","userAnswer":null,"userIsadmin":null,"userName":null,"userPasswd":null,"userQuestion":null},{"userAccount":"c","userAnswer":null,"userIsadmin":null,"userName":null,"userPasswd":null,"userQuestion":null},{"userAccount":"cc","userAnswer":null,"userIsadmin":null,"userName":null,"userPasswd":null,"userQuestion":null},{"userAccount":"ccc","userAnswer":null,"userIsadmin":null,"userName":null,"userPasswd":null,"userQuestion":null},{"userAccount":"d","userAnswer":null,"userIsadmin":null,"userName":null,"userPasswd":null,"userQuestion":null},{"userAccount":"dd","userAnswer":null,"userIsadmin":null,"userName":null,"userPasswd":null,"userQuestion":null},{"userAccount":"ddd","userAnswer":null,"userIsadmin":null,"userName":null,"userPasswd":null,"userQuestion":null},{"userAccount":"f","userAnswer":null,"userIsadmin":null,"userName":null,"userPasswd":null,"userQuestion":null},}],"total":15}

数据正常

将数据保存在json格式文件中访问,可以成功,但为什么这样就不能访问了。报错原因很明显了,没有配置input结果,

其实我们已经很清楚,返回的数据是正确的,但在后台,由于类型不匹配或者本身将结果集看错字符串,无法解析,所以报错。

当我们明确知道结果的时候可以将配置文件修改如下:

<action name="getalluserinfo" class="com.yusys.action.UserManageAction" method="getAllregisterUserInfo">
            <result name="success" type="json">
                 <param name="contentType">text/html</param>
            </result>
            <result name="input" type="json">
                 <param name="contentType">text/html</param>
            </result>
        </action>

也就是说,无论能否解析,我们都要获取得到的数据信息并返回给前台。这样前台得到数据就可以通过easyui的规则解析到datagrid中,正常显示。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值