spring+struts2+mybatis 框架下图片上传
来源:互联网 发布:建筑三维制图软件 编辑:程序博客网 时间:2024/05/17 18:27
一.html中<tr> <td colspan="2" align="left"><label for="typeahead">主管部门(公章):</label><form id="uploadForm1" enctype="multipart/form-data" target="submitFrame"><input type="file" name="upload" /> <button id="btnUpload1" type="button" class='avoid-this'>上传</button></form></td></tr><link href="css/uploadify.css" rel="stylesheet"><script src="js/jqueryjs/jquery.uploadify-3.1.min.js"></script>二、js中//上传$("#btnUpload1").bind( "click",function() {$.ajax({ url: '/xxxx/uploadOP.do', type: 'POST', cache: false, async :false, data: new FormData($('#uploadForm1')[0]), processData: false, contentType: false}).done(function(res) {// 保存成功后,初始化页面数据if (res.done !== undefined) {if(res.tb){ administrationsFile = res.tb ;$("#administrations").attr("src", administrationsFile);}} }).fail(function(res) {}); }); 三、action中 public class UploadOpAction extends ActionSupport {/** * 生成项目内唯一版本ID */private static final long serialVersionUID = -5210852842439224240L;Logger log = Logger.getLogger(this.getClass());private Map<String, Object> dataMap;public Map<String, Object> getDataMap() {return dataMap;}private String businessId;private String aa;// 封装上传文件域的属性private File upload;// 封装上传文件名的属性private String uploadFileName;// 封装上传文件类型的属性private String uploadContentType;public File getUpload() {return upload;}public void setUpload(File upload) {this.upload = upload;}public String getUploadFileName() {return uploadFileName;}public void setUploadFileName(String uploadFileName) {this.uploadFileName = uploadFileName;}public String getUploadContentType() {return uploadContentType;}public void setUploadContentType(String uploadContentType) {this.uploadContentType = uploadContentType;}@Overridepublic String execute() throws Exception {// 获取页面的请求信息HttpServletRequest request = ServletActionContext.getRequest();dataMap = new HashMap<String, Object>();HttpSession session = request.getSession(false);if (session == null) {dataMap.put("error", "session不存在");return SUCCESS;}businessId = (String) session.getAttribute("businessId");String realPath = ServletActionContext.getServletContext().getRealPath("/uploadFiles");String fileName=businessId+"."+uploadFileName;if (upload != null) {File savefile = new File(new File(realPath), fileName);String path = savefile.getAbsolutePath();int i = path.indexOf("CaiYiJia");aa = path.substring(i+9,path.length());dataMap.put("tb",aa);dataMap.put("done","上传成功!");if (!savefile.getParentFile().exists()) {savefile.getParentFile().mkdirs();}FileUtils.copyFile(upload, savefile);}return SUCCESS;}public String errorUtils(Map<String, Object> dataMap, Exception e,String value) {dataMap.put("error", value);e.printStackTrace();return SUCCESS;}}
1 0
- spring+struts2+mybatis 框架下图片上传
- ueditor在struts2下图片上传问题
- ueditor在struts2下图片上传问题
- 关于UEditor在struts2下图片上传问题
- 关于UEditor在struts2下图片上传问题
- ueditor在struts2下图片上传出错的问题的解决办法
- IE7下图片上传预览实现
- 解决 IE7下图片上传预览
- mybatis+spring+struts2框架整合
- mybatis+spring+struts2框架整合
- struts2+mybatis+spring框架整合
- mybatis+spring+struts2框架整合
- mybatis+spring+struts2框架整合
- Spring+Mybatis+Struts2框架搭建
- Struts2+spring+Mybatis框架整合
- struts2+spring+mybatis框架搭建
- IOS ARC模式下图片上传到FTP的详解
- IE6下图片的浏览剪裁与上传
- android6.0/7.0打开系统权限
- Scrapy递归抓取数据存入数据库(示例二)
- 网络传输中MAC地址表、ARP表和路由表详解
- 利用ftp命令+bat程序实现本地数据定时备份到服务器
- cogs 732. [网络流24题] 试题库
- spring+struts2+mybatis 框架下图片上传
- 在迅捷CAD编辑器中修改文字大小的办法
- nginx反向代理和正向代理
- vuejs安装
- AttributeError: 'module' object has no attribute 'best_partition'
- 七.Git常见问题及知识点补充2
- HDU 4460 Friend Chains 【bfs】【spfa】
- leetcode python
- Hello word!