【问题标题】:The server refused this request because the request entity is in a format not supported by the requested resource for the requested method服务器拒绝此请求,因为请求实体的格式不受所请求方法的请求资源支持
【发布时间】:2014-07-26 11:03:36
【问题描述】:

这是我的html页面

<form id="addsftpserver" name="addsftpserver" action="user-serverconfigurationSFTPSave" method="put"  enctype="multipart/form-data">

这个在spring conf xml中

<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
</bean>

Pom.xml

        <dependency>
    <groupId>commons-fileupload</groupId>
    <artifactId>commons-fileupload</artifactId>
    <version>1.2</version>
</dependency>

<!-- Apache Commons Upload -->
<dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.4</version>
</dependency>

还有我的控制器类

@RequestMapping(value = "/user-serverconfigurationSFTPSave", headers={"content-type=multipart/form-data"})
public String serverconfigurationSFTPSave(Model paramModel,@RequestParam(value = "privateKey", required = false) CommonsMultipartFile privateKey,<other params>,HttpServletRequest req) {}

但我收到以下错误: 服务器拒绝了请求,因为请求实体的格式不被请求的方法所请求的资源支持();

谁能指出我的错误

【问题讨论】:

    标签: spring-mvc web multipartform-data multipart thymeleaf


    【解决方案1】:

    如果您的表单方法是PUT,那么您需要有一个@RequestMapping 来映射到PUT。我认为您需要将method = RequestMethod.PUT 添加到您的@RequestMapping

    您可能希望方法(包括表单和@RequestMapping)为POST 而不是PUT,具体取决于您要执行的操作。

    【讨论】:

      猜你喜欢
      • 2019-04-28
      • 1970-01-01
      • 2018-01-19
      • 2015-05-19
      • 1970-01-01
      • 2021-01-04
      • 1970-01-01
      • 2018-06-24
      • 2013-03-19
      相关资源
      最近更新 更多