将文件从小程序上载到Spring MVC

将文件从小程序上载到Spring MVC,spring,model-view-controller,applet,Spring,Model View Controller,Applet,在我的应用程序中,我运行一个小程序来扫描客户端的图片。我需要上传扫描文件到服务器,然后到数据库。我可以通过在JSP中提交表单上传文件,但我需要小程序将文件发布到URL 任何hep都将不胜感激 代码如下: public static void main(String[] args) throws Exception { URL url = new URL("http://localhost:8080/spring/upload"); URLConnection connectio

在我的应用程序中,我运行一个小程序来扫描客户端的图片。我需要上传扫描文件到服务器,然后到数据库。我可以通过在JSP中提交表单上传文件,但我需要小程序将文件发布到URL

任何hep都将不胜感激

代码如下:

public static void main(String[] args) throws Exception {

    URL url = new URL("http://localhost:8080/spring/upload");
    URLConnection connection = url.openConnection();
    connection.setDoOutput(true);

    connection.setRequestProperty("Content-Type", "text/html;charset=UTF-8");
    connection.setRequestProperty("enctype", "multipart/form-data");

    DataOutputStream printout = new DataOutputStream(
        connection.getOutputStream());
    printout.write(FileUtils.readFileToByteArray(new File("c:\\img_khar.jpg")));

    printout.flush();
    printout.close();

    BufferedReader in = new BufferedReader(new InputStreamReader(
        connection.getInputStream()));

    String decodedString;

    while ((decodedString = in.readLine()) != null) {
        System.out.println(decodedString);
    }
    in.close();
}

对于这样的情况,我更喜欢使用apache的http客户端。它们提供了一个可以添加到HttpPost的MultipartEntity类


。你有什么问题?我有这个代码来发送文件,我想在Spring mvc上接收文件。但这不起作用。你能告诉我我错过了什么吗?你有没有想过“不工作”在描述实际问题时几乎毫无用处,而且几乎肯定不会导致有人提供解决方案。我们不能用魔法解决问题。对不起,我不能很好地解释这个问题。我终于明白了。谢谢