• 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

Servlet with XML

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi friends,

I've a client(Swing) formed an XML(using DOM) and sent it to servlet .How do i extract my DOM object from the HttpRequest Object ???

below is the piece of code which converts document object to string before sending to servlet

public static String convertDOM2String(Document document){
StringWriter writer=null;
try{
writer = new StringWriter();
(new XMLSerializer(writer, new OutputFormat())).serialize(document);
}
catch(Exception e)
{
System.out.println("prasha");
e.printStackTrace();
}
return writer.toString();
}

Can some one help me in this regard.Thanks in advance

thanks and regards
Prashanth
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How did you send it, as an HTTP form parameter or it the post, itself, an xml document?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The most basic idea is to use the request getInputStream method to get a stream readable by a parser. However, as Ben suggested, there are complications depending on how you sent it which may prevent this.

For example, note that if you use any request getParameter method, the servlet engine will have already read the stream and you wont be able to get it.

Bill
 
Prashanth Bhanu
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi friends,

Here is a piece of code which i used to build XML and sent to a servlet after serializing it...
thanks in advance


thanks
[ October 23, 2006: Message edited by: Ben Souther ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Javaranch tip:

If you are going to post more than a line or two of your code, wrap that
code in a set of UBB Code tags.
Doing so will help to preserve your code's indenting, making it easier to read.
If it is easier to read, more people will actaully read it and you will
stand a better chance of getting help with your question.
See UseCodeTags for more
help with UBB code tags.
 
Prashanth Bhanu
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi ,

Thanks,below code generates the DOM object,Serializes it and sends the serialized DOM object to TestServlet.I want to know how do i recover my DOM object from Request object at the server side i mean in servlet.
I tried using getInputstream() but it dint work ...please advice..thanks in advance

[list]//below 7 lines about opening a connection and building the DOM object
  • //below lines of codes creating root element,nodes and values


  • //below code creating 1st node and value


  • //below code creating 2nd node and value


  • //below code creating 3rd node and value


  • //Dom2string method is used to serialize and convert the DOM object to a string





  • thanks,
     
    Ben Souther
    Sheriff
    Posts: 13411
    Firefox Browser VI Editor Redhat
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Take a look at the getInputStream method of ServletRequest:
    http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletRequest.html#getInputStream&40;&41;
     
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic