Java servlet: transfer XML file to servlet

2019-08-28 21:21发布

问题:

I'm having a hard time deciding how to do this correctly so any input would be appreciated.

I'm trying to transfer my xml files from and applet to a servlet.

The solution I found for now is to pass the XML file as a string of data in a POST request.

When googling the problem I found the option of sending it by FTP.

What I would like to know is is there a way to simply transfer a XML file using HTTP

Jason

回答1:

You are on the correct track. Do a HTTP POST of the XML to a Servlet. But if the number of XML's to be transferred is huge then FTP might be the right option.



回答2:

HTTP protocol at its core isn't designed for file transfer. You have the basic GET and POST requests and that's pretty much it. Everything else is built up from those fundamentals. A common strategy is to encode file transfer as a higher-level protocol on top of HTTP POST. This requires a client and a server that understand this file transfer. I don't believe there has been any standardization of file transfer over HTTP.

I would not recommend using FTP as HTTP is more likely to tunnel properly through all the proxies that your users might have to contend with.



回答3:

You can try multipart POST or else you could try PUT HTTP methods to transfer the file as binary. In the servlet, you can reconstruct the data from the inputstream.