ajax上传图片
<input type="file" value="上传图片" name="photo" id="uploadPhoto" >
<button class="btn btn-default" type="button" onclick="uploadFile()" value="上传">上传</button> function uploadFile(){
action中:
private File photo; private SystemAttachmentService attachmentService; /get set 方法/
@Action("uploadfile") public String upLoadPic() throws Exception { SystemAttachment ssa = new SystemAttachment(); byte[] byte_photo = FileCopyUtils.copyToByteArray(getPhoto()); ssa.setContent(byte_photo); ssa.setCreateTime(new Date()); ssa.setCreateUser(getCurrentUserCode()); ssa.setDeleteFlag(0l); Long pk = attachmentService.saveSystemAttach(ssa); getJson().put("message",pk); return "forjson"; } @Action("showPic") public String showViewPic() { OutputStream out = null; SystemAttachment ss = null; if(null!=objectId){ ss = attachmentService.querySysPicForObjectId(objectId); }else{ ss = attachmentService.querySysPicForSyspk(sysPk); } try { out = getHttpServletResponse().getOutputStream(); if (null != ss) { try { out.write(ss.getContent()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }else{ out.write(attachmentService.querySysPicForObjectId(0l).getContent()); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { out.flush(); out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return null; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |