jfinal html5,jfinal移动端 HTML5 图片上传

html篇

var el=null;

var up = $('#upload').Huploadify({

auto:true,

fileTypeExts:'*.*',

multi:false,

showUploadedPercent:true,

showUploadedSize:true,

buttonText: '上传资料',

uploader:'uploadImage',

onUploadStart:function(file){

console.log(file.name+'开始上传');

el = $.loading({

content:'上传中...'

});

},

onUploadComplete:function(file,data){

//console.log(file.name+'上传完成');

//alert("file.name"+file.name);

//alert("date"+date);

var obj = JSON.parse(data);

$('[name="shop.shop_image"]').val(obj.path);

el.loading("hide");

}

});

JAVA篇:

public void uploadImage() {

//获取上传图片 上传

UploadFile uploadFile=this.getFile();

String fileName=uploadFile.getOriginalFileName();

String delImgName = fileName;

//获取上传文件

//UploadFile uf = getFile("Filedata", "mobile/setshop",DictUtil.maxImagSize,DictUtil.encoding);

//获取上传文件的类型  如 .jpg .png.....

String imageType=fileName.substring(uploadFile.getFileName().lastIndexOf("."),uploadFile.getFileName().length());

String imageName=System.currentTimeMillis()+imageType;

String rootPath =this.getSession().getServletContext().getRealPath("/upload/");

//拼接重新生成的图片名字

String file =rootPath+"/"+imageName;

//重命名

uploadFile.getFile().renameTo(new File(file));

ServiceHandler.delFile(rootPath, delImgName);

JSONObject urlJson = new JSONObject();

urlJson.put("imgName", imageName);

urlJson.put("path", file.replace(file, this.getCxt().concat("/upload/".concat(imageName))));

this.setAttr("shop_image", file.replace(file, this.getCxt().concat("/upload/".concat(imageName))));

renderJson(urlJson.toJSONString());

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值