Spring 3.0 FileUpload只有POST? [英] Spring 3.0 FileUpload only with POST?

查看:163
本文介绍了Spring 3.0 FileUpload只有POST?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我的控制器方法,它应该启用这个服务:

  @RequestMapping(value =/ {id},method = RequestMethod.PUT,headers =content-type = multipart / form-data)
public ResponseEntity< String> @ImageWithJsonParamater(@PathVariable(id)Long id,@RequestParam String json,@RequestParam MultipartFile customerSignFile){
// ...
}
pre>

问题是,服务器无法调度到这个方法:
MissingServletRequestParameterException:必需的字符串参数'json'不存在



如果将RequestMethod从PUT更改为POST,则一切正常。那么有人知道这个问题吗?

似乎不允许通过PUT传输表单数据。

我调试了一下,下面的方法在PUT的情况下返回false,但在POST的情况下返回true:

  public boolean isMultipart(HttpServletRequest request){
return(request!= null&&&&&ServletFileUpload.isMultipartContent(request));

$ / code $ / pre
$ b $ p



预先感谢!

解决方案

您无法按照HTML标准通过PUT发送表单数据。你只能通过PUT发送文件,在这种情况下,他们发送更高效,然后用POST(因为你不再有所有的多部分开销),但为了让你PUT监听服务器端组件实际接收文件通过PUT你必须确保你实际上发送一个PUT命令(例如通过javascript)。下面是一个使用JQuery的例子:

$ $ $'''file_upload')。fileUpload({
namespace:'file_upload ',
url:'/ path',
method:'PUT'
});


I am trying to upload a File with one parameter using spring 3.

This is my controller method which should enable this service:

@RequestMapping(value="/{id}", method = RequestMethod.PUT, headers="content-type=multipart/form-data")
public ResponseEntity<String> uploadImageWithJsonParamater(@PathVariable("id") Long id, @RequestParam String json, @RequestParam MultipartFile customerSignFile) {
    //...
}

The problem is, that the server cannot dispatch to this method: MissingServletRequestParameterException: Required String parameter 'json' is not present

If I change the RequestMethod from PUT to POST, everything is fine. So does anybody know the problem?

It seems that it isn't allowed to transmit form-data via PUT.

I debugged a little bit and the following method returns false in the PUT case but true in the POST case:

public boolean isMultipart(HttpServletRequest request) {
    return (request != null && ServletFileUpload.isMultipartContent(request));
}

I would appreciate any help!

Thanks in advance!

解决方案

You can't send form data via PUT as per the HTML standard. You can only send files via PUT, and in this case they're send more efficiently then with POST (because you no longer have all the multi-part overhead), but in order for you PUT listening server side component to actually receive a file via PUT you have to make sure that you actually send a PUT command to it (via javascript for instance). Here's an example that uses JQuery:

$('#file_upload').fileUpload({
    namespace: 'file_upload',
    url: '/path',
    method: 'PUT'
});

这篇关于Spring 3.0 FileUpload只有POST?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆