English 中文(简体)
Javagust OPTIONS cross-site data sent with >
原标题:JavaScript OPTIONS cross-site data sending with Firefox

I m having an issue with sending post data to the server when using Firefox. The server is running on Google App Engine.

我在 Java文中就座。

$.ajax({  
    url:  http://someurl/example/myform.json ,  
    type:  post ,  
    dataType:  json ,  
    data: {  
         value.title : title,  
         value.info.first : first,  
         value.info.second : value  
    },
    success: function(data) {  
        alert("success");  
    },  
    error: function(object, status, error) {  
        alert("error");  
    }  
});

我在服务器上。

@RequestMapping(value = "/myform.json", method = RequestMethod.POST)  
public ResponseEntity<String> create(@ModelAttribute("data") @Valid final Data data,  
final BindingResult result, final HttpServletResponse resp,) {  
  //process Data
}

So far so good, this worked on IE and Chrome without a problem. But then I found out it doesn t work on Firefox and that is because the browser first sends an OPTIONS method before actually posting anything so I went on and made the following to my server.

@RequestMapping(value = "/form.json", method = RequestMethod.OPTIONS)  
public ResponseEntity<String> options(
  final HttpServletResponse resp) {  
    final HttpHeaders responseHeaders = new HttpHeaders();  
    responseHeaders.set("Access-Control-Allow-Origin", "*");  
    responseHeaders.set("Access-Control-Allow-Methods", "GET, POST, OPTIONS");  
    responseHeaders.set("Access-Control-Allow-Headers", "Content-Type");  
    responseHeaders.set("Access-Control-Max-Age", "86400");  
    return new ResponseEntity<String>("",responseHeaders,HttpStatus.OK);  
  }
)

这里的问题是,这500人返回,而且该记录显示有警告。

java.security.AccessControlException: access denied (java.lang.RuntimePermission accessDeclaredMembers)  
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:355)  
at java.security.AccessController.checkPermission(AccessController.java:567)  
at java.lang.SecurityManager.checkPermission(Unknown Source)  
at com.google.apphosting.runtime.security.CustomSecurityManager.checkPermission(CustomSecurityManager.java:45)  
at java.lang.SecurityManager.checkMemberAccess(Unknown Source)  
at java.lang.Class.checkMemberAccess(Unknown Source)  
at java.lang.Class.getDeclaredMethods(Unknown Source)

任何建议?

问题回答

在你的要求下,你可以明确确定内容。 类型,即:

$.ajax({
    url:  http://someurl/example/myform.json ,
    type:  post ,
    dataType:  json ,
    contentType:  application/json ,
    data: {
         value.title : title,
         value.info.first : first,
         value.info.second : value
    }, complete: function() {
        alert("done");
    }
});

i 知道,由于你所描述的问题类型,我总是用X-site电话进行,并且已经做了相当一段时间(在服务器上安装电话之前,需要核对第1版)。

我相信,这将给你一个进一步阶段,如果不是成功的话。

jim





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签