如何从java控制器中的Ext.Ajax.request获取参数

发布于 2024-12-29 18:22:08 字数 1700 浏览 5 评论 0原文

我在检索使用 Ext.Ajax.request 传递给 JAVA 控制器类的参数时遇到一个问题。

我使用下面的代码向我的控制器发送请求,

Ext.Ajax.request({
             url : 'projecttask/GetprojectTasks.action',
             method: 'POST',
             jsonData: {
                sampledata: record.data
            },
            type: 'json',
            scope: this, // add the scope as the controller
             callback : function(options, success, response) {
                console.log('RESPONSE FROM SERVER :'+response);
             }
           });

我的java控制器方法接收请求,

@RequestMapping(value="/projecttask/GetprojectTasks.action")
    public @ResponseBody Map<String, ? extends Object> getprojectTasks(HttpServletRequest request,
            HttpServletResponse response,@RequestBody Project project) throws Exception {
        try {
            System.out.println("PROJECT ::"+project);
            System.out.println("RPOJECT DATA ::"+request.getParameter("sampledata"));
            Object data = request.getParameter("sampledata");
            Project prj = (Project) data;
            System.out.println("CREATE TASK DATA IS ::"+prj.getProjectid());            
            return null;            
        }catch(Exception e) {
            return getModelMapError("Error trying to create contact");
        }
    }

但它给了我下面提到的错误

org.codehaus.jackson.map.JsonMappingException: Unrecognized field "sampledata" (Class com.kintu.projectmgt.model.Project), not marked as ignorable

,所以我做错了什么,不允许我的函数获取作为参数传递的样本数据。我怎样才能得到我的参数传递值任何想法?

我的萤火虫显示样本数据包含所有值。请帮我尽快找到问题并解决。

我使用 Ext JS 4.0.2a 和 JAVA 作为我的服务器端技术。

I am having one problem in retrieving the parameter which i am passing using Ext.Ajax.request to my JAVA controller class.

I am sending request to my controller using below code

Ext.Ajax.request({
             url : 'projecttask/GetprojectTasks.action',
             method: 'POST',
             jsonData: {
                sampledata: record.data
            },
            type: 'json',
            scope: this, // add the scope as the controller
             callback : function(options, success, response) {
                console.log('RESPONSE FROM SERVER :'+response);
             }
           });

my java controller method to receive the request is

@RequestMapping(value="/projecttask/GetprojectTasks.action")
    public @ResponseBody Map<String, ? extends Object> getprojectTasks(HttpServletRequest request,
            HttpServletResponse response,@RequestBody Project project) throws Exception {
        try {
            System.out.println("PROJECT ::"+project);
            System.out.println("RPOJECT DATA ::"+request.getParameter("sampledata"));
            Object data = request.getParameter("sampledata");
            Project prj = (Project) data;
            System.out.println("CREATE TASK DATA IS ::"+prj.getProjectid());            
            return null;            
        }catch(Exception e) {
            return getModelMapError("Error trying to create contact");
        }
    }

but it gives me error mentioned below

org.codehaus.jackson.map.JsonMappingException: Unrecognized field "sampledata" (Class com.kintu.projectmgt.model.Project), not marked as ignorable

so what i am doing wrong which not allowed my function to get sampledata passed as parameters. How can i get my Parameters passed value any idea ?

My firebug shows that sampledata contains all values. Please help me to find the problem and solve it as soon as possible.

I am using Ext JS 4.0.2a and JAVA as my serverside technology.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

您可以使用它

String postParamsJSON = request.getReader().readLine();

来获取 POST 数据。

you can use

String postParamsJSON = request.getReader().readLine();

to get the POST data.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文