在做头像上传的过程中通常是将图片保存到数据库中,这里简单介绍一中将图片保存到数据库的方法:
jsp代码:
1 <div> 2 <input class="avatar-input" id="avatarInput" name="avatar_file" type="file" /> 3 <button class="btn btn-primary btn-block avatar-save" type="button" id="btn">完成</button> 4 </div> 5 //显示头像 6 <div> 7 <img id="image" src="${pageContext.request.contextPath}/Personal.do?method=Pictureshow" /> 8 </div>
js代码:
1 $("#avatarInput").wrap("<form id='myupload' action='${pageContext.request.contextPath}/Personal.do?method=Pictureupload' enctype='multipart/form-data' method='post' ></form>") 2 var formdata; 3 $("#avatarInput").change(function(){ 4 formdata=new FormData($("#myupload")[0]);