我的Coffescript请求:
d = { 'filter': "John Portella" };
$.ajax(
type: "POST",
dataType: "text/json",
data : JSON.stringify(d),
url: "/restricted/actionOnMultipleDatasets",
success: (data) ->
...
相关路线:
POST /restricted/actionOnMultipleDatasets controllers.ajax.AjaxDatasetOperations.actionOnMultipleDatasets()
和Controller动作
@SecuredAction(authorization = WithProvider.class, params = { "userpassword" })
public static Result actionOnMultipleDatasets() {
UserInfo userInfo = (UserInfo) ctx().args.get(SecureSocial.USER_KEY);
JsonNode json=request().body().asJson();
if(json==null){
return badRequest(Json.toJson("Data is not Json!"));
}
每当我请求该动作时,json为空。有没有人弄清楚为什么会这样? 作为附加信息,我使用securesocial。
我试图清理这个项目。什么都没发生。
相关的堆栈跟踪:
java.lang.NullPointerException
at controllers.ajax.AjaxDatasetOperations.actionOnMultipleDatasets(AjaxDatasetOperations.java:588)
at Routes$$anonfun$routes$1$$anonfun$applyOrElse$36$$anonfun$apply$36.apply(routes_routing.scala:497)
at Routes$$anonfun$routes$1$$anonfun$applyOrElse$36$$anonfun$apply$36.apply(routes_routing.scala:497)
at play.core.Router$HandlerInvoker$$anon$7$$anon$2.invocation(Router.scala:183)
at play.core.Router$Routes$$anon$1.invocation(Router.scala:377)
at play.core.j.JavaAction$$anon$1.call(JavaAction.scala:56)
at play.GlobalSettings$1.call(GlobalSettings.java:64)
at play.core.j.JavaAction$$anon$3.apply(JavaAction.scala:91)
at play.core.j.JavaAction$$anon$3.apply(JavaAction.scala:90)
at play.core.j.FPromiseHelper$$anonfun$flatMap$1.apply(FPromiseHelper.scala:82)
at play.core.j.FPromiseHelper$$anonfun$flatMap$1.apply(FPromiseHelper.scala:82)
at scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:278)
at scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:274)
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:29)
at play.core.j.HttpExecutionContext$$anon$2.run(HttpExecutionContext.scala:37)
at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:42)
at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:386)
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
答案 0 :(得分:2)
使用jquery发布时,请尝试添加以下行作为参数:
contentType:" application / json;字符集= UTF-8",
dataType:" json",