This week's book giveaway is in the Java 9 forum.
We're giving away four copies of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications and have Sander Mak & Paul Bakker on-line!
See this thread for details.
Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

struts return response and ajax  RSS feed

 
Ameet Topare
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i forward jsp in action class.

but how to get xml response in ajax script.
code in action class:

response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
response.getWriter().write("<valid>false</valid>");
.......
.....
return mapping.findForward("success");

and in script:
function processRequest() {
//alert('in process')
if (req.readyState == 4) {
if (req.status == 200) {
// Extract "true" or "false" from the returned data from the server.
// The req.responseXML should contain either <valid>true</valid> or <valid>false</valid>

var message = req.responseXML.getElementsByTagName("valid")[0].childNodes[0].nodeValue;

// Call "setMessageUsingDOM(message)" function to display
// "Valid User Id" or "Invalid User Id" message.

setMessageUsingDOM(message);
}
}
}

*****i am getting message as undefine
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37381
531
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ameet,
Welcome to JavaRanch!

The Struts action is returning the XML directly. Therefore you shouldn't be forwarding to a JSP. Each request/response pair only gets to do one thing. The XML is the one thing here. You return null rather than an ActionForward to handle the case of not forwarding to a JSP.
 
Ameet Topare
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok.

now as a response i m getting the complete html rather than small part of html. i.e
req.responseText returning me the complete html
 
Ameet Topare
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks man!!!

you explained ' null ' concept too good which clear whole idea..

its successfully run..

thanks once again..

this is my first post and i got too good reply.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37381
531
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ameet Topare:
thanks man!!!

You're welcome. Note that I'm female. Let's not assume everyone is male on the net
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!