JAVA-AOSUite文件,图片上传功能

更新时间:2024-01-29 18:58:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

JAVA-AOSUite文件,图片上传功能

关于jsp页面部分

Markup

关于上传图片js部分

Markup

function uploadPic(){

var record = AOS.selectone(g_dic); if(record){

f_pic_upload.loadRecord(record); }

if(!f_pic_upload.isValid()) {

Ext.Msg.alert(\系统提示\请选择文件后再上传!\ return; }

f_pic_upload.getForm().fileUpload = true; f_pic_upload.getForm().submit({

url:'do.jhtml?router=aosCeshiExtService.savePic&juid=${juid}', waitMsg:'文件上传中...', success: function() {

AOS.tip(\非常OK,上传成功!\ g_dic_store.reload(); w_pic_upload.hide();

},

failure: function() { w_pic_upload.hide();

AOS.tip(\文件上传失败!\ } });

}

关于后台接收部分的,以及转存

Java

/**

* 图片上传及保存 *

* @param httpModel */

@Transactional

publicvoidsavePic(HttpModel httpModel){ Dto inDto = httpModel.getInDto();

UploadFile uploadFile =newUploadFile(); AosCeshiPO aosCeshiPO =newAosCeshiPO(); aosCeshiPO.copyProperties(inDto); try{

Map map = uploadFile.ftpUpload(httpModel.getRequest());

aosCeshiPO.setFile_path(map.get(\).toString()); aosCeshiDao.updateByKey(aosCeshiPO); }catch(Exception e){

// TODO Auto-generated catch block e.printStackTrace(); }

String msg =\上传成功!'}\; httpModel.setOutMsg(msg); }

Java

String infoId =\;

public MapftpUpload(HttpServletRequest request){ Map map=newHashMap(); try{

MultipartHttpServletRequest multipartRequest = null; if(request instanceofMultipartHttpServletRequest){ try{

multipartRequest =(MultipartHttpServletRequest) request;

}catch(Exception ex){

ex.getMessage(); } }

if(multipartRequest != null){

Map fileMap = multipartRequest.getFileMap();

String newName =\; String url =\;

String paths =getWebPath(); String newNameSub=\;

for(Map.Entry entity : fileMap.entrySet()){ MultipartFile myfile = entity.getValue(); if(!myfile.isEmpty()){

//String infoId = request.getParameter(\

newName =getFileName(request,myfile);

newNameSub=newName.substring(newName.length()-3, newName.length());

if(newNameSub.equals(\)||newNameSub.equals(\)||newNameSub.equals(\)){

url = paths +\+newName; }elseif(newNameSub.equals(\)){

url = paths +\+newName; }else{

url = paths +\+newName; }

map.put(\,true); map.put(\, url); } } }

}catch(Exception e){

System.out.println(e.getMessage()); }

return map; }

public String getFileName(HttpServletRequest request,MultipartFile file)throws Exception{ // 转存文件

String

name=file.getOriginalFilename().substring(file.getOriginalFilename().indexOf(\), file.getOriginalFilename().length());//获取文件后缀

String newName = publicFile.createData().toString()+name;

String path = request.getSession().getServletContext().getRealPath(\);//项目存放路径

//截取字符串取后三位并转小写 String

nameSub=name.substring(name.length()-3,name.length()).toLowerCase(); if(nameSub.equals(\)||nameSub.equals(\)||nameSub.equals(\)){ path = path +\; }elseif(nameSub.equals(\)){

path = path +\; }else{

path = path +\; }

File targetFile =newFile(path, newName); if(!targetFile.exists()){

targetFile.mkdirs(); } try{

file.transferTo(targetFile); }catch(IllegalStateException e){ e.printStackTrace(); }catch(IOException e){

e.printStackTrace(); }

return newName; }

本文来源:https://www.bwwdw.com/article/oi4w.html

Top