将响应作为空。
这是我的密码
package com.javacodegeeks.enterprise.rest.jersey;
import java.util.Date;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
@Path("/")
public class HelloWorldREST {
@POST
@Path("/submitValue")
public Response responseMsg(@QueryParam("name") String name,@QueryParam("email") String email,@QueryParam("date") Date date) {
String output = date+email+name;
System.out.println(output);
return Response.status(200).entity(output).build();
}}
下面是对URL的调用
Ext.Ajax.request({
method : 'post',
url: 'rest/submitValue/',
//success: someFn,
//failure: otherFn,
params:
{
name: Ext.getCmp('name').getValue(),
email : Ext.getCmp('email').getValue(),
date : Ext.getCmp('date').getValue()
}
});当我发送这个请求参数时,我会被检查.所以它们的值不可能是空的。
发布于 2015-04-03 04:33:27
首先,rest方法,即HelloWorldREST.responseMsg不应该是post,因为它没有requestBody。这应该是一种方法。请始终记住,如果您希望将数据作为查询param(url param)发送,则始终使用get,如果您希望在请求体中发送数据,请使用POST。
现在,第二件事,因为您想要发送数据作为查询参数,您可以通过两种方式。确保从查询Ext.getCmp('name').getValue()获得值,可以在chrome控制台中检查它们的值。
Ext.Ajax.request({
url: 'rest/submitValue?name=' + Ext.getCmp('name').getValue() + '&email=' + Ext.getCmp('email').getValue() + '&date=' + Ext.getCmp('date').getValue(),
method: 'GET',
success: function (response) {
},
failure:function(response){
}
});
Ext.Ajax.request({
url: 'rest/submitValue?name=' + Ext.getCmp('name').getValue() + '&email=' + Ext.getCmp('email').getValue() + '&date=' + Ext.getCmp('date').getValue(),
method: 'GET',
params: {
name: Ext.getCmp('name').getValue(),
email : Ext.getCmp('email').getValue(),
date : Ext.getCmp('date').getValue()
}
success: function (response) {
},
failure:function(response){
}
});发布于 2015-04-02 18:30:56
您可以使用data:而不是params将数据发送到服务器:
Ext.Ajax.request({
method : 'post',
url: 'rest/submitValue/',
//success: someFn,
//failure: otherFn,
data:
{
name: Ext.getCmp('name').getValue(),
email : Ext.getCmp('email').getValue(),
date : Ext.getCmp('date').getValue()
}
});我在这里看到了三件事
type:而不是method:类型定义:来自jquery网站:
type (default: 'GET')
Type: String
An alias for method. You should use type if you're using versions of jQuery prior to 1.9.0.@Component或@Controller注释。@Consumes(MediaType.APPLICATION_JSON)。这可能会有帮助..。
https://stackoverflow.com/questions/29419558
复制相似问题