• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

struts return response and ajax

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
I found a beautiful pie. And a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic