首页 > 代码库 > bootstrap 图片上传实例
bootstrap 图片上传实例
引入的包:
import java.io.File; import java.util.Iterator; import java.util.UUID; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileItemFactory; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.io.FileUtils; import org.apache.struts2.ServletActionContext; import com.gzzs.util.service.HandlerPath; import com.opensymphony.xwork2.ActionSupport;
html:
<div style="margin-top: 10px; margin-left: 180px"> <input id="specialrecommendfile" type="file" size="30" name="file"> <button type="button" onclick="UploadSpecialRecommendPic()" class="btn btn-warning btn-lg">上传</button> <input type=hidden class="span5" id="specialRecommendPic" name="riIndexPic"> </div>
js:
function UploadSpecialRecommendPic() { $.ajaxFileUpload({ url : '/GZZSServer/s_util/uploadSpecialRecommendPic.action', secureuri : false, fileElementId : 'specialrecommendfile', dataType : 'json', success : function(d, status) { var data = http://www.mamicode.com/eval('(' + d + ')');>
action:public String uploadSpecialRecommendPic() { try { String path; path = "C://"; FileUtils.copyFile(file, new File(path)); result = "{flag:\"1\",msg:\"操作成功\",path:\"" + HandlerPath.getHostSimulateAuthorLogoPath() + fileFileName + "\",picName:\"" + fileFileName + "\"}"; return SUCCESS; } catch (Exception e) { e.printStackTrace(); result = "{flag:\"0\",msg:\"操作失败\"}"; return SUCCESS; } }
实例图片:
bootstrap 图片上传实例
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。