1

I can send data to a jsp page using the method below. but I need to open the same page and show the data (uuid) to the user. how can i send data with this method to test.jsp and open the page(test.jsp)?

function EditRule(i){
var uuid = document.getElementsByName('uuid'+i).item(0).value;


xmlhttp = GetXmlHttpObject();
if (xmlhttp == null) {
    alert("you have to use newer versions of browser");
    return;
}
var url = "test.jsp";
var parameters = "uuid=" + uuid;
xmlhttp.onreadystatechange = getEditRule;
xmlhttp.open("POST", url, true);

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

xmlhttp.onreadystatechange = getEditRule;
xmlhttp.send(parameters);


}
function getEditRule() {
if (xmlhttp.readyState == 4) {
     var input = document.getElementById('temp');
     input.value = xmlhttp.responseText.trim();

}
}
Aliaksei Bulhak
  • 6,078
  • 8
  • 45
  • 75
MohammadZoghi
  • 578
  • 1
  • 7
  • 17

1 Answers1

2

I don't think you understand what a JSP page is because you can't "send data to a JSP page using AJAX". The JSP page only exists on the server not in the client's browser. On the server the JSP page is compiled into a client readable format (HTML) and then sent to the client in that format. So if you want a JSP page to eventually cause an AJAX request to be sent, you would embed the Javascript into the JSP page that fires the AJAX. Then you would also have a Javascript function capable of parsing the response. Examples for all of this is available in the JQuery documentation.

KyleM
  • 4,445
  • 9
  • 46
  • 78
  • did you look at my code? I send data to server side jsp page using this code. and i want to know if there is any way to open -as you said- the client readable format of the same jsp page that i process my data in it? – MohammadZoghi Apr 21 '13 at 20:21
  • BalusC has covered this in this excellent Q/A: [How to use Servlets and Ajax?](http://stackoverflow.com/q/4112686/1065197) – Luiggi Mendoza Apr 21 '13 at 20:21