使用springmvc提交put请求时提示 Request method 'POST' not supported
来源:互联网 发布:腾讯mac管家 编辑:程序博客网 时间:2024/06/05 23:00
出错时编写的代码如下:
①web.xml
<!-- 配置springmvc的 DispatcherServlet ctrl+alt+向上键 -->
<servlet>
<servlet-name>springDispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springDispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- 配置 :把POST请求转为DELETE、PUT请求 ctrl+shift+t -->
<filter>
<filter-name>HiddenHttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HiddenHttpMethodFilter</filter-name>
<url-pattern>/</url-pattern>
</filter-mapping>
</web-app>
②请求界面
<form:form action="emp" method="post" modelAttribute="employee">
<!-- path属性对应name属性值 -->
<c:if test="${employee.id == null }">
LastName:<form:input path="lastName"/>
</c:if>
<c:if test="${employee.id != null }">
<form:hidden path="id"/>
<!-- 对于_method不能使用form:hiddden 标签,因为modelAttribute中没有_method这个属性 -->
<input type="hidden" name="_method" value="put"/>
</c:if>
...........
</form>
③处理器
@ModelAttribute
public void getEmployee(@RequestParam(value="id",required=false) Integer id,
Map<String,Object> map){
if(id != null){
map.put("employee", employeeDao.get(id));
}
}
@RequestMapping(value="/emp", method=RequestMethod.PUT)
public String update(Employee employee){
employeeDao.save(employee);
return "redirect:/emps";
}
⑥以上完成后运行时出现错误提示 Request method 'POST' not supported
这是因为请求页面的form标签的action不是绝对路径导致的,因此,在编写时,应尽量写成绝对路径!!!
<form:form action="${pageContext.request.contextPath }/emp" method="post" modelAttribute="employee">
- 使用springmvc提交put请求时提示 Request method 'POST' not supported
- springmvc解决 405 request method post not supported(Request method 'POST' not supported)
- curl发送post请求出现:Request method 'post' not supported
- request method 'post' not supported
- Request method 'POST' not supported
- SpringMVC中出现”HTTP Status 405 - Request method 'PUT' not supported”
- Spring MVC-Request method 'POST' not supported:
- request method 'post' not supported问题解决
- org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'PUT' not supported
- spring MVC form表单提交用RequestMethod.POST报错 : Request method 'GET' not supported
- 关于HTTP Status 500 - Request method 'POST' not supported分析
- HTTP Status 405 - Request method 'POST' not supported (Spring MVC)
- Spring MVC Request method 'POST' not supported错误
- JQuery ajax提交表单时<button>按钮引起的 Request method 'GET' not supported错误!
- Request method 'GET' not supported
- Request method 'GET' not supported
- Spring MVC出现POST 400 Bad Request &405 Request method 'GET' not supported
- SpringBoot 调用ajax POST 方法报Request method 'POST' not supported解决方法
- kubernetes 1.2版弹性伸缩HPA
- java并发编程:同步工具类
- ExtJS6.2 Hello MVC 实例 web开发
- Java快速排序算法
- 保存图片到sd卡之后在相册显示
- 使用springmvc提交put请求时提示 Request method 'POST' not supported
- java 内存流 利用内存流复制文件
- Hive的几种常见的数据导入方式
- 分布式事务学习(一)
- 使用Jquery实现顶部导航栏在页面滑动到自身所在位置之后固定在顶部的效果
- Spring--IoC--基于XML的DI-异类抽象Bean
- redis 使用
- 利用JavaScript、Ajax及CSS3实现图片预加载
- Centos-6.5-Server图解安装