相关资源下载:upload
1:jsp代码:
导入jquery.upload.js和jquery-1.7.2.js
添加调用js的代码:<a href="javascript:void(0)" rel="external nofollow" onclick="doUpload()">上传</a>
在底部写:
<iframe style="position:absolute;top:-9999px" src="<%=basePath%>/resources/upload/upload.htm"/></iframe>
2:js代码:
/*文件上传*/function doUpload() {// 上传方法$.upload({// 上传地址url:window.basePath+'/reply/imageUpload', // 文件域名字fileName: 'uploadfile', // 其他表单数据params: {},// 上传完成后, 返回json, textdataType: 'json',// 上传之前回调,return true表示可继续上传onSend: function() {return true;},onSubmit: function(){},// 上传之后回调onComplate: function(data) {if(data.msg){}else{alert("上传图片出错!");}}});}
3:后台代码:
/*** 图片上传本地服务器* @param request* @param response* @return*/@RequestMapping(value="imageUpload")@ResponseBodypublic Object imageUpload(HttpServletRequest request,HttpServletResponse response){Map<String, Object> map=new HashMap<String, Object>();UploadUtil uploadUtil = new UploadUtil();try {String url = uploadUtil.excelUpload(request, response);// 文件上传} catch (IOException e) {e.printStackTrace();}return map;}
新闻热点
疑难解答