Java 检索从post ajax req发送的数据

Java 检索从post ajax req发送的数据,java,ajax,servlets,struts,Java,Ajax,Servlets,Struts,我需要在ajax post请求中向服务器发送大量字符串。如果将其添加到url的末尾,则可以使用服务器中的request.getParameter()方法获取 但是我不能在url中附加大字符串,所以我想使用XMLHttpRequest的send()方法发送,而不是将它附加到url 但我无法在服务器中使用request.getParameter()检索相同的内容 如何在j2ee服务器中检索从ajax请求发送的数据? 请指导我。无论您是否使用AJAX,更改的Url的实际长度都有限制 最好POST发布您

我需要在ajax post请求中向服务器发送大量字符串。如果将其添加到url的末尾,则可以使用服务器中的request.getParameter()方法获取

但是我不能在url中附加大字符串,所以我想使用XMLHttpRequest的send()方法发送,而不是将它附加到url

但我无法在服务器中使用request.getParameter()检索相同的内容

如何在j2ee服务器中检索从ajax请求发送的数据?
请指导我。

无论您是否使用AJAX,更改的Url的实际长度都有限制

最好
POST
发布您的所有数据。下面是使用AJAX执行相同操作的代码:

var http = new XMLHttpRequest(); // Get the correct http object depending on browser
var url = "YOUR_URL.php";
var params = "param1=value1&param2=value2";
http.open("POST", url, true);

//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");

http.onreadystatechange = function() { // Call a function when the state changes.
    if(http.readyState == 4 && http.status == 200) {
        alert(http.responseText);
    }
}
http.send(params);

希望这有帮助。

如果您有一个ajax密集型Web应用程序,我建议使用javascript库(如jquery)来处理ajax。在jQuery中,可以按如下方式执行:

$.post("your_url.php", { param1: "value1", param2: "value2" } );

顺便提一下您将无法使用
request.getParameter(“param1”)检索所有变量等。