ServletFileUpload upload = new ServletFileUpload(factory);
upload.setSizeMax(Constants.UPLOAD_MAX_SIZE);
try {
List fileItems = upload.parseRequest(request);
Iterator iter = fileItems.iterator();
Advertisement ad = new Advertisement();
ad.setMerchant(_m);
ad.setUser(rtUser);
ad.setUrl(null);
ad.setSJSJ(new Date());
ad.setQX(10000);
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if (!item.isFormField()){
String fileName = item.getName();
if (fileName != null && fileName.length() != 0) {
BufferedInputStream bis = new BufferedInputStream(item.getInputStream());
String _fn = fileName.substring(fileName.lastIndexOf(System.getProperty("file.separator"))+1);
String _ed = _fn.substring(_fn.indexOf('.'));
String path = ManagementAction.class.getClassLoader().getResource("/").getPath();
File file = new File(path);
File p_file = new File(file.getParent());
String url = p_file.getParent()+System.getProperty("file.separator")+"merchant_picture"+System.getProperty("file.separator")+new Date().getTime()+"_"+_m.getID();
boolean suc = new File(p_file.getParent()+System.getProperty("file.separator")+"merchant_picture"+System.getProperty("file.separator")+new Date().getTime()+"_"+_m.getID()).mkdirs();
if(suc){
File _new = new File(url+System.getProperty("file.separator")+_m.getID()+_ed);
_new.createNewFile();
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(_new));
Streams.copy( bis, bos, true);
ad.setTPLJ(_new.getPath());
ad.setTplx("02");
}
}
}else{
String tpmx = item.getString();
ad.setTpmx(tpmx);
}
}
advertisementDao.createAdvertisement(ad);
} catch (FileUploadException e) {
e.printStackTrace();