在我的记忆中,我通过将额外的库放入我的构建路径中解决了同样的问题:
代码语言:javascript复制commons-fileupload-1.2.2.jar
commons-io-2.1.jar我希望这能对你有所帮助。
编辑。
好的。我终于有时间讨论这个问题了。首先,为什么要使用standart java特性来构建rest服务(annotations @POST,@Path)?因为对于Spring,最好使用spring MVC来进行REST。互联网上有很多关于这方面的信息。这是reference documentation中的一个特殊部分。这里还有good article on IBM site。关于如何用Spring MVC构建REST控制器的很好的描述是用Spring in Action (last 3-d edition)编写的。
下面是我如何实现简单的文件上传功能:
Rest控制器:
代码语言:javascript复制@Controller
@RequestMapping("/rest/files")
public class FilesController {
...
@RequestMapping(value="/rest/files", method=RequestMethod.POST)
public String uploadFile(@RequestParam("name") String name,
@RequestParam("file") MultipartFile file) {
try {
if (!file.isEmpty()) {
byte[] bytes = file.getBytes();
// store the bytes somewhere
return "redirect:uploadSuccess";
} else {
return "redirect:uploadFailure";
}
}
catch (Exception ex)
{
}
return "/testFileDownload";
}
}html:
代码语言:javascript复制
Please upload a file
dispatcher-servlet.xml中的视图解析器配置:
代码语言:javascript复制
我希望我没有浪费我的时间,这对你来说仍然是必要的。)
编辑2个
下面是very good tutorial,其中描述了如何使用Spring3.1构建RESTful web服务。