Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PUT上不支持Spring MVC-405方法_Spring_Spring Mvc - Fatal编程技术网

PUT上不支持Spring MVC-405方法

PUT上不支持Spring MVC-405方法,spring,spring-mvc,Spring,Spring Mvc,我对我面临的一个问题有点困惑,在更新用户对象时,我反复得到405方法是不允许的。但是,控制器代码和HTML表单似乎是正确的。如果我将RequestMethod.PUT更改为RequestMethod.POST,它可以正常工作。我是不是遗漏了什么 我正在使用以下URL方案 /user [GET] - user list /user/new [GET] - form to create a new user /user [POST] - create user /user/{id}/edit [GE

我对我面临的一个问题有点困惑,在更新用户对象时,我反复得到405方法是不允许的。但是,控制器代码和HTML表单似乎是正确的。如果我将RequestMethod.PUT更改为RequestMethod.POST,它可以正常工作。我是不是遗漏了什么

我正在使用以下URL方案

/user [GET] - user list
/user/new [GET] - form to create a new user
/user [POST] - create user
/user/{id}/edit [GET] - form to edit user
/user/{id} [PUT] - update the user
/user/{id} [DELETE] - delete the user
从HTTPFox捕获的HTTP流量

请求头

(Request-Line)  POST /searchtool/user/12 HTTP/1.1
Host    localhost:8080
User-Agent  Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0
Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language en-US,en;q=0.5
Accept-Encoding gzip, deflate
Referer http://localhost:8080/searchtool/user/12/edit
Cookie  JSESSIONID=685471429B1BC65305E2B0390F91CBC1
Connection  keep-alive
Cache-Control   max-age=0
Content-Type    application/x-www-form-urlencoded
Content-Length  128
响应头

(Status-Line)   HTTP/1.1 405 Method Not Allowed
Server  Apache-Coyote/1.1
Allow   DELETE, PUT
Content-Type    text/html;charset=ISO-8859-1
Content-Language    en-US
Transfer-Encoding   chunked
Date    Tue, 27 May 2014 16:01:01 GMT
发布数据

_method PUT
id  12
firstName   User
lastName    Test
email   test@test.com
userName    test1
password    
password-confirm    
role    2
控制器代码段

@Secured(value={"ROLE_ADMIN"})
@Transactional
@RequestMapping(value="/user/{id}", method=RequestMethod.PUT)
public String userUpdate(User user, BindingResult userBinding, Model model, @PathVariable long id) {

    if (userBinding.hasErrors()) {
        return (String.format("user/{%s}/edit", String.valueOf(user.getId())));
    }

    try {
        userService.updateUser(user);
    }
    catch (Exception e) {
        logger.error("Unable to update user", e);
    }

    return "redirect:/user";
}
JSP


错误:无法创建用户,请查看下面突出显示的字段

用户添加
名字 姓 电子邮件 用户名 密码 确认密码 角色 拯救 取消

您必须在web.xml中使用,请参见下文

<filter>
    <filter-name>hiddenmethodfilter</filter-name>
    <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>hiddenmethodfilter</filter-name>
    <servlet-name>dispatchers-name</servlet-name>
</filter-mapping>

隐藏方法过滤器
org.springframework.web.filter.hiddenhttmpmethodfilter
隐藏方法过滤器
调度员姓名

并在html/jsp中使用Spring tld表单标记,并在表单中包含\u method=PUT

有些浏览器不支持表单的PUT。包括最新版本的IE和FireFox?看起来像。。。是的,我在web.xml文件中丢失了那个片段。谢谢
<filter>
    <filter-name>hiddenmethodfilter</filter-name>
    <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>hiddenmethodfilter</filter-name>
    <servlet-name>dispatchers-name</servlet-name>
</filter-mapping>