Java Upload Applet Request

2019-08-27 12:47发布

Can someone please show me/link a simple multipart form data, http post file upload script I can convert to an applet? Looking for someone that who will go easy on me, I've been after this goal for over a month now and just need this. I'm very new to java and have had several small victories on my way to finishing this project but I absolutely need help with this.

I've already got a few signed scripts working, so I've done a lot on my own, but I need one here bad. I'm just so confused.

1条回答
ら.Afraid
2楼-- · 2019-08-27 13:21

The easiest approach to do an http post from your applet is to use Apache HTTP Client. You'll need to add the jar file to your applet's classpath. A simple example:

HttpClient client = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://example.com/test");
MultipartEntity entity = new MultipartEntity();
entity.addPart("file1", new FileBody(new File("filetoUpload.jpg"), "application/jpg"));
post.setEntity(entity);
client.execute(post)
client.getConnectionManager().shutdown();

If for some reason you cannot use HTTP Client you can still do it with java.net.URL but it's a lot more complicated:

Using java.net.URLConnection to fire and handle HTTP requests

查看更多
登录 后发表回答