上传文件相关代码

	/*  At this point the application doesn't actually associate the images with a portfolio.  This just saves the file to the filesystem */
	
	private void addImage ( File pic, String fileName, String fileSystemHome ) throws IOException 
	{
		/* add image to the portfolio and save image file to local filesystem */
		  FileInputStream in = null;
	        FileOutputStream out = null;
	        
	        String directoryName = fileSystemHome;
	        String localPath=getRequest().getSession().getServletContext().getRealPath("/");
	        File dir = new File ( localPath+directoryName);
	        boolean b=false;
	        if ( !dir.exists() ){
	           b=dir.mkdirs();
	        }
	        String targetPath =  dir.getPath() + dir.separator + fileName;
	        
	        File picDestination = new File ( targetPath);
	        try {
	            in = new FileInputStream( pic );
	            out = new FileOutputStream( picDestination );
	            int c;

	            while ((c = in.read()) != -1) {
	                out.write(c);
	            }

	        }finally {
	            if (in != null) {
	                in.close();
	            }
	            if (out != null) {
	                out.close();
	            }
	        }
		
	}

if(caseId>0){

				fileSystemPath="page/videoManage/pic";
				//String picTime=fileSystemPath+"/"+getUploadPicFileName().substring(0,6 );
				String picTime=fileSystemPath+"/"+getUploadPicFileName().substring(0,6 )+"/"+String.valueOf(caseId)+"/before";
				try {
					addImage( getUploadPic(), getUploadPicFileName(), picTime  );
				} catch (IOException e) {
					this.addFieldError("OpErr", "上传视频截图失败,请查看异常日志");
					return "err";
				}
				try{
					caseImage.setId(getUploadPicFileName().substring(0, getUploadPicFileName().indexOf(".")));
					caseImage.setCaseId(caseId);
					caseImage.setImageUrl(picTime+"/"+getUploadPicFileName());
					caseImage.setCaseType(0);
					caseImage.setImageType(1);
					Long ong=caseInfoBS.addCaseImage(caseImage);
				}catch (Exception e) {
					this.addFieldError("OpErr", "添加视频截图到数据库失败,请查看异常日志");
					return "err";
				}
//				try {
//					this.getResponse().getWriter().write("案件保存成功");
//				} catch (IOException e) {
//					e.printStackTrace();
//				}
				ActionContext.getContext().put("resultBoolean", "1");
			}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值