wood burning stoves 2.0*
The moose likes Struts and the fly likes problem in implementing the AJAX with Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "problem in implementing the AJAX with Struts" Watch "problem in implementing the AJAX with Struts" New topic
Author

problem in implementing the AJAX with Struts

murali kankanala
Ranch Hand

Joined: Nov 15, 2004
Posts: 110
hi friends,

i have the issue AJAX with Struts.

i am providing the code here.

in JSP JavaScript

request.onreadystatechange = replyMethod(request);
request.open('GET',url,true);
request.send(null);

function replyMethod()
{
var message = request.responseXML.getElementsByTagName("message")[0];
}

here i am getting problem , i am unable to get the responseXML object.



in Action Class perform()

response.setContentType("text/xml");
response.setHeader("Cache-Control","no-cache");
response.getWriter().write("some value");

return mapping.findForward("Success");



my issue is i am able to get the request.responseText
but i am unable to get the request.responseXML

how to return the xml from Action class


please help me in this way
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

This is not an advanced Java question; it might be a Javascript question, or a Struts question, but it's not a Java question at all. I suspect it's an issue with understanding Struts, so I'm moving this to our Struts forum. Please stop posting these questions in JiG (Advanced) -- it's not where they belong!


[Jess in Action][AskingGoodQuestions]
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
Have you tried returning valid XML from your action? Since, "some value" is not a valid xml document, my understanding is that responseXML will be null.

- Brent
murali kankanala
Ranch Hand

Joined: Nov 15, 2004
Posts: 110
hi Brent,


If i provide the code as below in Action class

response.getWriter().write("<message><item-name>Box</item-name></message>");

Is it going to read properly in JavaScript

var message = request.responseXML.getElementByTagName("message")[0];



And tell me whether the Action class is going to validate the XML or JavaScript is going to validate the XML. Where it compare the XML with DTD or Schema.


please provide proper answer , if possible provide some sample code with Action class.
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
You are ahead of me when it comes to Ajax, because I have not actually written any code. My understanding is that responseXML uses an XML parser to build a DOM object representing the XML document. If it cannot parse the XML document, then it...well, I just ran a quick search and got this:

"if the response entity body is not valid XML, this method returns the Document object that was parsed so that you can access the ParseError object through it."

This seems odd. Have you tried using responseText to see what is being returned? Now that I look at your Action code, I would return null instead of mapping.findForward().

- Brent
murali kankanala
Ranch Hand

Joined: Nov 15, 2004
Posts: 110
hi Brent,

when i return mapping.findforward("jsp");

if i call request.responseText() it is giving Jsp's html content as output.

but not what i have returned response.getWriter().write("<h>hello</h>");
murali kankanala
Ranch Hand

Joined: Nov 15, 2004
Posts: 110
Hi

i found the one solution that if i return Null in mapping.findFowrad(null);

then if u read the request.responseText then it will give the XML content which we have written in Action class.


but still i am not getting why request.responseXML giving NULL. value
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
You indicated tha the code in you JSP was:

request.onreadystatechange = replyMethod(request);
request.open('GET',url,true);
request.send(null);

function replyMethod()
{
var message = request.responseXML.getElementsByTagName("message")[0];
}


Make request a global variable and change:

request.onreadystatechange = replyMethod(request);

to

request.onreadystatechange = replyMethod;


Merrill
Consultant, Sima Solutions
murali kankanala
Ranch Hand

Joined: Nov 15, 2004
Posts: 110
Hi Merrill ,

Yes i am using the Global request variable only.

Although it is giving Null when i print request.responseXML.

If u have any code that is working in your plate kindely u can send it to me
 
Don't get me started about those stupid light bulbs.
 
subject: problem in implementing the AJAX with Struts