前台
<%@ 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=utf-8" >
<title > Insert title here</title >
<script type ="text/javascript" src ="${pageContext.request.contextPath }/static/jquery/jquery-1.8.3.js" > </script >
</head >
<body >
<form id ="userForm" >
<p > 姓名:<input id ="uname" type ="text" name ="userName" /> </p >
<p > 头像:<input type ="file" name ="file" />
<button type ="button" value ="保存" onclick ="save()" > 出来把</button >
</form >
<script type ="text/javascript" >
function save () {
var formData = new FormData($("#userForm" )[0 ]);
var name = $("#uname" ).val();
formData.append("name" , name);
$.ajax({
url : '${pageContext.request.contextPath}/a/shApply/update' ,
type : 'POST' ,
data : formData,
async : false ,
cache : false ,
contentType : false ,
processData : false ,
success : function (data) {
alert(data);
},
error : function (data) {
alert(data);
}
});
}
</script >
</body >
</html >
后台
@Controller
@RequestMapping (value = "a/shApply" )
public class ShApplyController extends BaseController {
@RequestMapping (value = "update" )
@ResponseBody
public String update (HttpServletRequest request, @RequestParam (value = "file" , required = false )
MultipartFile file,
String name) {
System.out.println(name);
return null ;
}