• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Navitaging to some different page

 
Mohammad Alam khan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried everything but in vain.. I have a jsp page and a text area on it. When i put my request which is in xml format inside the text area and clicking on the submit button present on jsp page, the request is calling some servlet on the server. The servlet is processing the request and sending the response using response.setContentType("text/xml"). so the output we are getting on the browser rather than console. The problem is that the response i am getting is on a different jsp page rather than the same jsp page on which i have a text area and i have submitted the request. Iwant my response on the same provided text area rather than a new html/jsp page. Please help. I could not place all the codes as they are on client network.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13073
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you write the servlet that is getting the initial request?

Bill
 
Mohammad Alam khan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
NO...I haven't written the servlet on my own. It is on the client network. but this the flow of the application which i have already explained. i need to change in my jsp file so that the response will come only on the text area provided in the jsp page (where i have pasted my request).
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So your requirement is that the response shouldn't replace the whole page which submitted the request, but only part of it?

If that's the case, then you would need to do something involving AJAX to submit the request and then put the response in a particular place. This doesn't have anything to do with servlets, as it's Javascript code which you run on the client.

Or do I misunderstand your requirement?
 
Mohammad Alam khan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,my ajax some how looks like this :
function getXMLHttpRequest() {
var xmlHttpReq = false;
if (window.XMLHttpRequest) {
xmlHttpReq = new XMLHttpRequest();
} else if (window.ActiveXObject) {
try {

xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
} catch (exp1) {
try {

xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
} catch (exp2) {
xmlHttpReq = false;
}
}
}
return xmlHttpReq;
}

function makeRequest() {
var xmlHttpRequest = getXMLHttpRequest();
xmlHttpRequest.onreadystatechange = getReadyStateHandler(xmlHttpRequest);
xmlHttpRequest.open("POST", "http://abc:8080/someservletServlet/", true);
xmlHttpRequest.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
xmlHttpRequest.send(null);
}


function getReadyStateHandler(xmlHttpRequest) {

return function() {
if (xmlHttpRequest.readyState == 4) {
if (xmlHttpRequest.status == 200) {

document.getElementById("xml").value = xmlHttpRequest.responseText;
} else {
alert("HTTP error " + xmlHttpRequest.status + ": " + xmlHttpRequest.statusText);
}
}
};
}
but somehow the servlet is not bringing the response it should bring. can you help
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot make an Ajax request to a server that did not serve the page unless you do something special such as JSONP or CORS.

Do you also realize that all that code can condense down into one or two lines if you use jQuery?
 
Roger F. Gay
Ranch Hand
Posts: 408
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:You cannot make an Ajax request to a server that did not serve the page unless you do something specials such as JSONP or CORS.

Do you also realize that all that code can condense down into one or two lines if you use jQuery?


It's already been reduced to a single call in JavaScript:
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roger F. Gay wrote:It's already been reduced to a single call in JavaScript

Umm, right.
 
Mohammad Alam khan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks roger & bear for your help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic