Spring MVC Framework:具有PUT方法的MultipartResolver [英] Spring MVC Framework: MultipartResolver with PUT method

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

问题描述

我正在使用框架3.2.3发行Spring mvc应用程序

I'm developing a spring mvc app with framework 3.2.3.RELEASE

在我的应用中,我使用StandardServletMultipartResolver处理Multipart,但是使用apache commons-fileupload 1.3,情况是一样的.

In my app I handle Multipart with StandardServletMultipartResolver, but with apache commons-fileupload 1.3 the things are the same.

我想知道为什么isMultipart方法的实现只考虑POST方法,而不考虑PUT方法.如果要更新实体和相关文件,则必须使用POST进行.

I would like to know why the implementation of isMultipart method take in account only POST method, and not PUT method. If I want to update an entity and the related file I must do it with a POST.

查看org.springframework.web.multipart.support.Standard ServletMultipartResolver:

Looking at org.springframework.web.multipart.support.Standard ServletMultipartResolver:

public boolean isMultipart(HttpServletRequest request) {
    // Same check as in Commons FileUpload...
    if (!"post".equals(request.getMethod().toLowerCase()) ) {
        return false;
    }
    String contentType = request.getContentType();
    return (contentType != null && contentType.toLowerCase().startsWith("multipart/"));
}

在org.apache.commons.fileupload.servlet.ServletFileU pload中,我有:

while in org.apache.commons.fileupload.servlet.ServletFileU pload I have:

public static final boolean isMultipartContent(HttpServletRequest request) {
    if (!POST_METHOD.equalsIgnoreCase(request.getMethod() )) {
        return false;
    }
    return FileUploadBase.isMultipartContent(new ServletRequestContext(request));
}

不是至关重要的事情,实际上只是使用POST方法对PUT起作用..但是我想理解为什么不考虑PUT!

Is not a thing of vital importance, in fact just use the POST method intead of PUT works.. But I want to undertand why PUT is not taken into account!

感谢您的任何回复 马可

Thank you for any reply Marco

推荐答案

RFC说

RFC said

http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6

POST请求中的URI标识将处理封闭实体的资源.该资源可能是数据接受过程,通向其他协议的网关,或者是接受注释的单独实体.相比之下,PUT请求中的URI标识请求中包含的实体-用户代理知道URI的意图,并且服务器绝不能尝试将请求应用于其他资源.

The URI in a POST request identifies the resource that will handle the enclosed entity. That resource might be a data-accepting process, a gateway to some other protocol, or a separate entity that accepts annotations. In contrast, the URI in a PUT request identifies the entity enclosed with the request -- the user agent knows what URI is intended and the server MUST NOT attempt to apply the request to some other resource.

因此PUT请求代表一个资源.
但是多部分意味着在单个主体中具有多个资源.

So PUT request represent a single resource.
But multiparts means multiple resources in a single body.

http://www.w3.org/Protocols/rfc1341/7_2_Multipart.html

对于多部分消息,其中将一个或多个不同的数据集组合在一个正文中,则多部分"的Content-Type字段必须出现在实体的标题中.然后,主体必须包含一个或多个主体部分",每个主体部分"之前是封装边界,最后一个是封闭"边界.

In the case of multiple part messages, in which one or more different sets of data are combined in a single body, a "multipart" Content-Type field must appear in the entity's header. The body must then contain one or more "body parts," each preceded by an encapsulation boundary, and the last one followed by a closing boundary.

因此,根据PUT的语义,请求与多部分数据不匹配. 并且POST是匹配的,因为POST请求的请求URI是封闭实体的处理程序".

Therefore by semantic of PUT request doesn't match with multipart data. And the POST is matched because requested URI of POST request is "handler of enclosed entities".

这篇关于Spring MVC Framework:具有PUT方法的MultipartResolver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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