• Post Reply Bookmark Topic Watch Topic
  • New Topic

POST file and parameters to servlet from Java Application?  RSS feed

 
peter greaves
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi everyone
i want to post an XML file to a servlet. i have this working by sending the entire file as the content of the servlet like this:

this seems to be working fine. but now i need to extend this by sending some parameters with the POST. i don't want to use the query string for these params. i have been reading that attributes are sent as name/value pairs in the POST's content so a=foo&b=bar etc. am atuck with the general approach.
should i make a string out of the params and send it at the front of the xml file, and make the XML content itself into an attribute of the post e.g.
a=b&c=d&content=<! etc
and how would i handle this on the server side? could i use HttpUtils.parsePostData(), even with what might be a big xml document? would i need to encode the string?
or is there a better approach? i have very limited implementation time so simple will win over comprehensive

thanks a lot for any advice and help,
peter
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the parameters you need to send are simple strings, you could attach them to the request with setRequestProperty( name, value ) and read them on the servlet side with getHeader.
Bill
 
peter greaves
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bill
thanks very much - your suggestion worked just fine for me. have to admit that i was finding the thicket of name/value pair possibilities in the request a bit inpenetrable. your suggestion was right on the money.
thanks for the books btw!!
regs
peter
[ July 07, 2003: Message edited by: peter greaves ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!