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

来源:互联网 发布:数据包分析软件 编辑:程序博客网 时间:2024/06/17 23:58

前台

<%@ 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" onclick="editUser()">修改用户</a> <a
            href="javascript:void(0)" class="easyui-linkbutton"
            iconCls="icon-remove" plain="true" onclick="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" onclick="updateUser()" style="width:90px">保存</a> <a
            href="javascript:void(0)" class="easyui-linkbutton"
            iconCls="icon-cancel" onclick="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
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 苹果七发烫厉害怎么办 苹果手机延迟高怎么办 王者荣耀总是卡怎么办 王者荣耀卡屏怎么办 王者荣耀网络延迟怎么办 荣耀8手机卡了怎么办 荣耀v10有点卡怎么办 荣耀10有点卡怎么办 8g内存吃鸡会崩怎么办 玩看门狗很卡怎么办 拼多多人数不够怎么办 玩cf想吐怎么办 玩手机头晕恶心怎么办 玩手机头疼恶心怎么办 看手机想吐怎么办 英雄联盟取名后怎么办 王者荣耀改名重复怎么办 刺激战场改名重复怎么办 省钱快报忘记密码怎么办 手机直播网速卡怎么办 触手tv直播黑屏怎么办 酷狗id密码忘记怎么办 打游戏网络不稳定怎么办 电脑打字法没了怎么办 家庭版密钥专业版系统怎么办 win7应用程序不能启动怎么办 win7用户密码忘记了怎么办 win7用户密码忘了怎么办 windows开不了机怎么办 网卡被卸载了怎么办 win7注销黑屏了怎么办 w7密码忘了怎么办 笔记本电脑键盘进水了怎么办 笔记本键盘进水了怎么办 笔记本进水键盘失灵怎么办 win7进不了系统怎么办 电脑显示屏两边黑屏怎么办 win8关机关不了怎么办 win10没激活黑屏怎么办 忘了产品密钥怎么办 小马易贷逾期怎么办