• 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

Submit xml data to an Url from a servlet

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can i submit xml data to an Url from a servlet?
XML data is created on a string buffer and now i want to submit it to a url. This should be done with out using attributes..............ie should be writen to the stream.
Please help me out..........

Thanks in advance.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Strictly speaking this is an IO question and has nothing to do with Servlets. It doesn't matter whether you do this from a Servlet or any other class. you can use the java.net package or a stronger version in the Jakarta HttpComponents.

Dave
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've used a bit of code like this in the past.

private void sendXml(String xml, URL endPoint) {
try {
OutputStreamWriter out = null;
try {
URLConnection connection = endPoint.openConnection();
connection.setDoOutput(true);
out = new OutputStreamWriter(connection.getOutputStream());
out.write(xml);
out.flush();
} finally {
if (out != null) {
out.close();
}
}
} catch (IOException e) {
//Handle exception
}
}
 
Ajith George
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Chris. But how can i read the response back from the server. i tried input stream but it is returning internal server error.
 
Ranch Hand
Posts: 489
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You may want to look into this article that mentions the numerous URLConnection pitfalls and how to avoid them.

ram.
 
I am mighty! And this is a mighty small ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic