Java 从android手机向本地web服务器发送图片

Java 从android手机向本地web服务器发送图片,java,android,image,spring,webserver,Java,Android,Image,Spring,Webserver,我已经搜索了很多地方,找到了一些将图片发送到web服务器的方法。到目前为止,没有一个对我很有效。也许我开始的时候弄错了,但我已经为控制器编写了代码,该控制器负责处理接收到的图片 我使用的是TomcatWeb服务器,并使用Spring工具套件和MVC框架在服务器端编写了所有代码。控制器的编写方式如下: @RequestMapping(value = "/upload", method = RequestMethod.POST) public String handleFormUpload(@Req

我已经搜索了很多地方,找到了一些将图片发送到web服务器的方法。到目前为止,没有一个对我很有效。也许我开始的时候弄错了,但我已经为控制器编写了代码,该控制器负责处理接收到的图片

我使用的是TomcatWeb服务器,并使用Spring工具套件和MVC框架在服务器端编写了所有代码。控制器的编写方式如下:

@RequestMapping(value = "/upload", method = RequestMethod.POST)
public String handleFormUpload(@RequestParam("name") String name, @RequestParam("file") MultipartFile file) throws IOException {
    if (!file.isEmpty()) {
        byte[] bytes = file.getBytes();
        // store the bytes somewhere
        return "redirect:uploadSuccess";
       } else {
        return "redirect:uploadFailure";
       }
}
<html>
<head>
    <title>Upload a file please</title>
</head>
<body>
    <h1>Please upload a file</h1>
    <form method="post" action="/form" enctype="multipart/form-data">
        <input type="text" name="name"/>
        <input type="file" name="file"/>
        <input type="submit"/>
    </form>
</body>
jsp的编写方式如下:

@RequestMapping(value = "/upload", method = RequestMethod.POST)
public String handleFormUpload(@RequestParam("name") String name, @RequestParam("file") MultipartFile file) throws IOException {
    if (!file.isEmpty()) {
        byte[] bytes = file.getBytes();
        // store the bytes somewhere
        return "redirect:uploadSuccess";
       } else {
        return "redirect:uploadFailure";
       }
}
<html>
<head>
    <title>Upload a file please</title>
</head>
<body>
    <h1>Please upload a file</h1>
    <form method="post" action="/form" enctype="multipart/form-data">
        <input type="text" name="name"/>
        <input type="file" name="file"/>
        <input type="submit"/>
    </form>
</body>

请上传一个文件
请上传一个文件

所以基本上我想知道:
如何编写将图片从手机发送到web服务器的类/方法


我感谢所有能得到的帮助

我正在使用commons fileuploadUse(搜索)Apache HTTP组件或URLConnection。由于我不是最伟大的程序员,如果我能得到一个适合我具体情况的示例代码,我将不胜感激。那太棒了!我发现自己很难应用这些!使用搜索功能,这个网站上有大量的例子。