图片上传

 第一步: jspapache

批量图片导入:<input id="fileimg" type="file" name="fileimg"  >服务器

  <input id="submitImage" type="submit" value=" 提交 ">jsp

第二步:Action 类ide

private File fileimg;oop

private static boolean excelLock = false;this

private final static String filePre = "/data/homes/ftesitemanage/temp/";url

/**spa

*     excel 导入excel

* @return图片

*/

public String import_excel(){

if (excelLock) return null;

try {

excelLock = true;

String activityId=getParameter("excelActivityid");

 

String filePath = "";

   File newFile=null;

   filePath = filePre+System.currentTimeMillis();

if("excel".equals(fileType)){ 

newFile = new File( filePath+".xls");

FileUtils.copyFile(file, newFile);

if(fileimg!=null){

newFile=new File(filePre);

if(!newFile.exists()){

FileUtil.makeParent(newFile);

}

derExcute.unZipFile(fileimg,filePre);

}

if(!"".equals(cooperationService.importExcelCooperation(activityId, filePath+".xls"))){ //说明有分配新短号失败的经纪人

this.setWriterPrint("<script>parent.showfailSpan('0');</script>");

return null;

}else{

this.setWriterPrint("<script>parent.showfailSpan('1');</script>");

return null;

}

}

} catch (Exception e){

e.printStackTrace();

}finally {

excelLock = false;

}

return null;

}

第三步: ServiceImpl 处理类

import org.apache.commons.io.FileUtils;

public String validateUrlToLocal(String str,String filePath) {

if (str.indexOf("pic.homescn.com") > 0) {//服务器上的图片,就直接剪切对应的地址

return str.substring(str.indexOf(".com/") + 5);

}else{//若是文本直接就是图片名称: 就加上文件路径

String localImg=filePre+str;

String httpurl=doImgPath();

try {

FileUtils.copyFile(new File(localImg),new File(httpurl)); //上传图片到指定服务器地址

str=httpurl.substring(httpurl.indexOf("ftepic/")+7);

} catch (IOException e) {

System.out.println("上传图片异常: "+e.getLocalizedMessage());

}

}

//把图片下载到本地

// String filename = str.substring(str.lastIndexOf("/"));

// WebUtil.saveUrlToLocal(localPath + filename, str);

return str;

}

相关文章
相关标签/搜索