Java Upload Applet Request

纵饮孤独 提交于 2019-12-11 19:46:58

问题


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:


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



来源:https://stackoverflow.com/questions/10341467/java-upload-applet-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!