Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet with XML

 
Prashanth Bhanu
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • 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
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How did you send it, as an HTTP form parameter or it the post, itself, an xml document?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • 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
  • 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 Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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,
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic