springMVC delete和PUT提交数据

web.xml:

<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>

jsp :

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>用户列表</h1>
<a href="javascript:void(0)" onclick="deleteById()">删除</a>
<a href="javascript:void(0)" onclick="updateById()">修改</a>
<form action="1" method="post" id="deleteform">
<input type="text" name="_method" value="DELETE"/>
<button>提交</button>
</form>
<form action="1" method="post" id="updateform">
<input type="text" name="_method" value="PUT"/>
<button>PUT提交</button>
</form>
<script type="text/javascript">
function deleteById(){
document.getElementById('deleteform').submit();
}
function updateById(){
document.getElementById('updateform').submit();
}
</script>
</body>
</html>

controlller:

  

@RequestMapping(value="/{id}",method=RequestMethod.DELETE)
public String delete() {
System.out.println("delete");
return "redirect:/user/list";
}
@RequestMapping(value="/{id}",method=RequestMethod.PUT)
public String update() {
System.out.println("update");
return "redirect:/user/list";
}

 

posted @ 2018-11-15 11:27  星云惊蛰  阅读(987)  评论(0)    收藏  举报