jtables(jquery api),struts2作为模型部分

时间:2016-08-04 06:37:55

标签: java ajax struts2 struts2-jquery jquery-jtable

我正在使用jsp / struts和hibernate开发基于ajax的CRUD表应用程序,我无法使用struts在我的java类中检索json数据,使用ajax调用从jsp发送json数据

Index.jsp页面

$(document).ready(function() {
        $('#PersonTableContainer').jtable({
            title : 'TODO TABLE',
            selecting : true,
            multiselect : true,
            selectingCheckboxes : true,
            paging : true,
            sorting : true, 

            actions : {
                listAction : '<s:url action="listaction"/>',
                createAction : '<s:url action="createaction"/>',
                updateAction : '/updateaction',
                deleteAction : '/deleteaction'
            },

                fields : {
                    studentId : {
                        title : 'Student Id',
                        width : '30%',
                        key : true,
                        list : true,
                        edit : false,
                        create : true
                    },
                    name : {
                        title : 'Name',
                        width : '30%',
                        edit : true
                    },
                    department : {
                        title : 'Department',
                        width : '30%',
                        edit : true
                    },
                    emailId : {
                        title : 'Email',
                        width : '20%',
                        edit : true
                    }
                },


            });
        $('#PersonTableContainer').jtable('load');
    });

在我的java类中,我试图恢复我的java类中的json数据,但值为null

public String create() throws IOException {
        System.out.println("inside create");
        record = new Bean();

        record.setStudentId(studentId);
        record.setName(name);
        record.setDepartment(department);
        record.setEmailId(emailId);

        try {
            // Create new record
            String name=record.getName();
            System.out.println(name);
            String dept=record.getDepartment();
            System.out.println("dep");
            System.out.println(dept);
            result = "OK";

        } catch (Exception e) {
            result = "ERROR";
            message = e.getMessage();
            System.err.println(e.getMessage());
        }
        return Action.SUCCESS;  
    }

struts.xml中

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

 <struts>  


<constant name="struts.devMode" value="true" />
<package name="default" extends="json-default">


 <action name="*action" class="com.programmingfree.controller.FullStack"
            method="{1}">


        <interceptor-ref name="json">
            <param name="enableSMD">true</param>

        </interceptor-ref>


            <result type="json">/index.jsp</result>
</action>



    </package>

我查看了发送的数据

data sent from server

但在java类中

but in java class the values are coming as null

0 个答案:

没有答案